@font-face {
  font-family: "Rubik";
  src: url("/fonts/Rubik-Variable.ttf") format("truetype");
  font-weight: 300 900;
  font-display: swap;
}

/* Цвета бренда: гранат, саперави, золото, чурчхела, лоза, крем */
:root {
  --bg: #FFF4E6;
  --surface: #FFFFFF;
  --surface-2: #FBE9D7;
  --text: #3A0A14;
  --text-2: #7A5A50;
  --primary: #D7263D;
  --primary-press: #B81E33;
  --on-primary: #FFFFFF;
  --accent: #E8751A;
  --gold: #F4B942;
  --deep: #5B0F1F;
  --success: #2E7D4F;
  --border: rgba(91, 15, 31, 0.12);
  --focus: #E8751A;
  --shadow: 0 1px 2px rgba(0, 0, 0, 0.05), 0 2px 8px rgba(0, 0, 0, 0.04);
  --radius: 16px;
  --radius-s: 10px;
  --tabs-h: 64px;
  --ease: cubic-bezier(0.2, 0.8, 0.2, 1);
}

:root[data-theme="dark"] {
  --bg: #1C0B10;
  --surface: #2A1218;
  --surface-2: #361820;
  --text: #FFF4E6;
  --text-2: #D9BFB3;
  --primary: #F0475C;
  --primary-press: #D7263D;
  --on-primary: #FFFFFF;
  --accent: #F39A4C;
  --success: #5CC28A;
  --border: rgba(255, 244, 230, 0.12);
  --shadow: none;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 400 16px/1.5 "Rubik", system-ui, -apple-system, "Segoe UI", sans-serif;
  min-height: 100dvh;
  padding-bottom: calc(var(--tabs-h) + env(safe-area-inset-bottom) + 16px);
  -webkit-tap-highlight-color: transparent;
}
button, input, textarea { font: inherit; color: inherit; }
button { cursor: pointer; touch-action: manipulation; }
img { display: block; max-width: 100%; }
h1, h2, p { margin: 0; }
:focus-visible { outline: 3px solid var(--focus); outline-offset: 2px; border-radius: 6px; }
.sr-only {
  position: absolute; width: 1px; height: 1px; overflow: hidden;
  clip: rect(0 0 0 0); white-space: nowrap;
}
.icon {
  width: 20px; height: 20px; flex: none;
  fill: none; stroke: currentColor; stroke-width: 1.75; stroke-linecap: round; stroke-linejoin: round;
}

/* ---------- шапка ---------- */
.top {
  position: sticky; top: 0; z-index: 20;
  background: var(--bg);
  padding: 0 16px 12px;
  padding-top: calc(var(--tg-safe-area-inset-top, 0px) + var(--tg-content-safe-area-inset-top, 0px));
  border-bottom: 1px solid var(--border);
}
/* полоса орнамента: болнисские кресты на гранатовом */
.ornament {
  height: 8px; margin: 0 -16px;
  background-color: var(--primary);
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='8'%3E%3Cpath d='M8 1.2l.9 1.9 1.9.9-1.9.9L8 6.8l-.9-1.9L5.2 4l1.9-.9z' fill='%23F4B942'/%3E%3C/svg%3E");
  background-repeat: repeat-x;
}
.brand { display: flex; align-items: center; gap: 10px; padding: 12px 0 10px; }
.brand-name { font-weight: 600; font-size: 20px; letter-spacing: -0.01em; }

.search {
  position: relative; display: flex; align-items: center;
  background: var(--surface); border: 1px solid var(--border); border-radius: 12px;
  min-height: 46px; padding: 0 4px 0 12px; gap: 8px; color: var(--text-2);
}
.search:focus-within { border-color: var(--accent); }
.search input {
  flex: 1; min-width: 0; border: 0; background: none; outline: none;
  color: var(--text); font-size: 16px; padding: 10px 0;
}
.search input::-webkit-search-cancel-button { display: none; }
.search-clear {
  width: 40px; height: 40px; border: 0; background: none; display: grid; place-items: center;
  color: var(--text-2); border-radius: 10px;
}

main { padding: 16px; max-width: 720px; margin: 0 auto; }

/* ---------- фильтры ---------- */
.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chips-sub { margin-top: 10px; }
.chips-sub:empty { display: none; }
.chip {
  display: inline-flex; align-items: center; gap: 6px;
  min-height: 44px; padding: 0 14px;
  border: 1px solid var(--border); border-radius: 999px;
  background: var(--surface); color: var(--text);
  font-size: 15px; font-weight: 500;
  transition: background-color 160ms var(--ease), color 160ms var(--ease), border-color 160ms var(--ease);
}
.chip .icon { width: 18px; height: 18px; }
.chip small { color: var(--text-2); font-size: 13px; font-weight: 400; }
.chip[aria-selected="true"], .chip[aria-pressed="true"] {
  background: var(--deep); border-color: var(--deep); color: #FFF4E6;
}
.chip[aria-selected="true"] small, .chip[aria-pressed="true"] small { color: #F4D9C4; }
:root[data-theme="dark"] .chip[aria-selected="true"],
:root[data-theme="dark"] .chip[aria-pressed="true"] { background: var(--gold); border-color: var(--gold); color: #3A0A14; }
:root[data-theme="dark"] .chip[aria-selected="true"] small,
:root[data-theme="dark"] .chip[aria-pressed="true"] small { color: #5B0F1F; }
.chip-sub { min-height: 40px; font-size: 14px; }

.list-head {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  margin: 18px 0 12px; flex-wrap: wrap;
}
.count { color: var(--text-2); font-size: 14px; }
.sort { display: flex; background: var(--surface-2); border-radius: 10px; padding: 3px; }
.sort button {
  border: 0; background: none; min-height: 36px; padding: 0 12px;
  border-radius: 8px; font-size: 14px; color: var(--text-2);
}
.sort button[aria-pressed="true"] { background: var(--surface); color: var(--text); font-weight: 500; box-shadow: var(--shadow); }

/* подписка на текущий магазин или категорию */
.follow {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  background: var(--surface); border: 1px solid var(--border);
  border-radius: 12px; padding: 12px 12px 12px 16px; margin-bottom: 14px;
}
.follow-title { font-weight: 600; }
.follow-text { color: var(--text-2); font-size: 13px; line-height: 1.4; }

/* ---------- карточки акций ---------- */
.grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; }
@media (min-width: 560px) { .grid { grid-template-columns: repeat(3, minmax(0, 1fr)); } }

.card {
  position: relative; display: flex; flex-direction: column;
  background: var(--surface); border-radius: var(--radius); overflow: hidden;
  box-shadow: var(--shadow); border: 1px solid var(--border);
  text-align: left; padding: 0; color: inherit; text-decoration: none;
  transition: transform 140ms var(--ease);
}
.card:active { transform: scale(0.98); }
.card-img { aspect-ratio: 1 / 1; background: #FFFFFF; display: grid; place-items: center; overflow: hidden; }
.card-img img { width: 100%; height: 100%; object-fit: contain; padding: 10px; }
.card-img.cover img { object-fit: cover; padding: 0; }
.card-img .placeholder { width: 44%; opacity: 0.9; }

/* ценник со скидкой, как на логотипе */
.pct {
  position: absolute; top: 10px; left: 0;
  background: var(--primary); color: var(--on-primary);
  font-weight: 600; font-size: 15px; line-height: 1;
  padding: 6px 10px 6px 8px;
  border-radius: 0 8px 8px 0;
  font-variant-numeric: tabular-nums;
}
.fresh {
  position: absolute; top: 10px; right: 10px;
  background: var(--success); color: #fff; font-size: 12px; font-weight: 500;
  padding: 4px 8px; border-radius: 999px;
}
.card-body { padding: 10px 12px 12px; display: flex; flex-direction: column; gap: 4px; flex: 1; }
.card-store { color: var(--text-2); font-size: 13px; font-weight: 500; }
.card-title {
  font-size: 14px; line-height: 1.35; font-weight: 500;
  display: -webkit-box; -webkit-line-clamp: 3; -webkit-box-orient: vertical; overflow: hidden;
}
.card-meta { color: var(--text-2); font-size: 12px; display: flex; align-items: center; gap: 4px; }
.card-meta .icon { width: 14px; height: 14px; }
.prices { margin-top: auto; padding-top: 6px; display: flex; align-items: baseline; gap: 8px; flex-wrap: wrap; font-variant-numeric: tabular-nums; }
.price { font-weight: 600; font-size: 18px; color: var(--success); }
.old { color: var(--text-2); font-size: 13px; text-decoration: line-through; }

/* скелетон при загрузке */
.skeleton { pointer-events: none; }
.skeleton .card-img, .skeleton .line {
  background: linear-gradient(90deg, var(--surface-2) 0%, var(--surface) 50%, var(--surface-2) 100%);
  background-size: 200% 100%; animation: shimmer 1.2s linear infinite;
}
.skeleton .line { height: 12px; border-radius: 6px; margin: 4px 0; }
@keyframes shimmer { to { background-position: -200% 0; } }

.state { text-align: center; padding: 40px 16px; color: var(--text-2); }
.state h2 { color: var(--text); font-size: 18px; margin-bottom: 6px; }
.state .btn { margin-top: 16px; }

/* ---------- кнопки ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  min-height: 48px; padding: 0 20px; border: 0; border-radius: 12px;
  background: var(--primary); color: var(--on-primary); font-weight: 600; font-size: 16px;
  transition: background-color 140ms var(--ease), opacity 140ms var(--ease);
}
.btn:active { background: var(--primary-press); }
.btn[disabled] { opacity: 0.5; cursor: default; }
.btn-small { min-height: 44px; padding: 0 14px; font-size: 15px; flex: none; }
.btn-ghost { background: var(--surface); color: var(--text); border: 1px solid var(--border); }
.btn-ghost:active { background: var(--surface-2); }
.btn-wide { width: 100%; margin-top: 16px; }
.btn.is-on { background: var(--surface-2); color: var(--text); }
.spinner {
  width: 18px; height: 18px; border-radius: 50%;
  border: 2px solid currentColor; border-right-color: transparent;
  animation: spin 0.7s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- подписки ---------- */
.view-title { font-size: 24px; font-weight: 600; letter-spacing: -0.01em; }
.lead { color: var(--text-2); margin-top: 6px; }
.section-title { font-size: 15px; font-weight: 600; margin: 24px 0 8px; padding: 0; }
.hint { color: var(--text-2); font-size: 13px; line-height: 1.45; margin-top: 4px; }

.rows { list-style: none; margin: 0; padding: 0; background: var(--surface); border-radius: var(--radius); border: 1px solid var(--border); overflow: hidden; }
.row {
  display: flex; align-items: center; gap: 12px; width: 100%;
  min-height: 56px; padding: 8px 14px; border: 0; background: none; text-align: left;
}
.rows li + li .row { border-top: 1px solid var(--border); }
.row-icon { width: 36px; height: 36px; border-radius: 10px; background: var(--surface-2); display: grid; place-items: center; color: var(--deep); flex: none; }
:root[data-theme="dark"] .row-icon { color: var(--gold); }
.row-text { flex: 1; min-width: 0; }
.row-text small { display: block; color: var(--text-2); font-size: 13px; }

.switch {
  width: 48px; height: 28px; border-radius: 999px; background: var(--border); position: relative; flex: none;
  transition: background-color 180ms var(--ease);
}
.switch::after {
  content: ""; position: absolute; top: 3px; left: 3px; width: 22px; height: 22px; border-radius: 50%;
  background: #fff; box-shadow: 0 1px 3px rgba(0,0,0,.25); transition: transform 180ms var(--ease);
}
[aria-checked="true"] .switch { background: var(--success); }
[aria-checked="true"] .switch::after { transform: translateX(20px); }

.add-word { display: flex; gap: 8px; margin-top: 10px; }
.add-word input, #lead-text, #lead-contact {
  flex: 1; min-width: 0; min-height: 48px; padding: 12px 14px; font-size: 16px;
  background: var(--surface); border: 1px solid var(--border); border-radius: 12px; outline: none;
}
.add-word input:focus, #lead-text:focus, #lead-contact:focus { border-color: var(--accent); }
.field-error { color: var(--primary); font-size: 14px; margin-top: 6px; min-height: 0; }
.field-error:empty { display: none; }
.words { list-style: none; padding: 0; margin: 10px 0 0; display: flex; flex-wrap: wrap; gap: 8px; }
.word {
  display: inline-flex; align-items: center; gap: 2px; padding-left: 14px;
  background: var(--surface); border: 1px solid var(--border); border-radius: 999px; font-size: 15px;
}
.word button { width: 40px; height: 40px; border: 0; background: none; display: grid; place-items: center; color: var(--text-2); border-radius: 999px; }
.word .icon { width: 18px; height: 18px; }

.segmented { display: grid; grid-template-columns: repeat(4, 1fr); gap: 6px; background: var(--surface-2); padding: 4px; border-radius: 12px; }
.segmented button {
  min-height: 44px; border: 0; border-radius: 9px; background: none; color: var(--text-2);
  font-weight: 600; font-variant-numeric: tabular-nums;
}
.segmented button[aria-checked="true"] { background: var(--surface); color: var(--text); box-shadow: var(--shadow); }

/* ---------- заявка ---------- */
.kinds { border: 0; margin: 20px 0 0; padding: 0; }
.kinds legend { margin-top: 0; }
.kinds > div { display: grid; gap: 8px; }
.kind {
  display: flex; align-items: center; gap: 12px; min-height: 56px; padding: 10px 14px;
  background: var(--surface); border: 1px solid var(--border); border-radius: 12px; cursor: pointer;
}
.kind input { width: 20px; height: 20px; accent-color: var(--primary); margin: 0; flex: none; }
.kind:has(input:checked) { border-color: var(--primary); box-shadow: inset 0 0 0 1px var(--primary); }
.kind small { display: block; color: var(--text-2); font-size: 13px; line-height: 1.4; }
.field-label { display: block; font-weight: 600; font-size: 15px; margin: 20px 0 8px; }
#lead-text { width: 100%; resize: vertical; line-height: 1.45; }
#lead-contact { width: 100%; }

.done { text-align: center; padding: 48px 16px; }
.done-icon { width: 56px; height: 56px; color: var(--success); stroke-width: 2; margin: 0 auto 12px; }
.done h2 { font-size: 22px; margin-bottom: 6px; }
.done p { color: var(--text-2); margin-bottom: 20px; }

/* ---------- нижние вкладки ---------- */
.tabs {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 30;
  display: grid; grid-template-columns: repeat(3, 1fr);
  background: var(--surface); border-top: 1px solid var(--border);
  padding-bottom: env(safe-area-inset-bottom);
}
.tabs button {
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px;
  min-height: var(--tabs-h); border: 0; background: none; color: var(--text-2); font-size: 12px; font-weight: 500;
}
.tabs button[aria-current="page"] { color: var(--primary); }
.tabs button[aria-current="page"] .icon { stroke-width: 2.25; }

.toast {
  position: fixed; left: 50%; bottom: calc(var(--tabs-h) + env(safe-area-inset-bottom) + 12px); z-index: 40;
  transform: translate(-50%, 12px); opacity: 0; pointer-events: none;
  background: var(--deep); color: #FFF4E6; padding: 10px 16px; border-radius: 12px;
  font-size: 14px; max-width: calc(100% - 32px); text-align: center;
  transition: opacity 200ms var(--ease), transform 200ms var(--ease);
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: 0.01ms !important; transition-duration: 0.01ms !important; }
}
