/* static/css/app.css */
:root {
  --ink: #111;
  --ink-2: #4a4a4a;
  --line: #e3e3e3;
  --bg-2: #f4f4f4;
  --gray: #6f6f6f;
  --gray-dark: #3f3f3f;
  --radius: 12px;
  --tap: 52px;
  --tap-sm: 44px;

  /* Единый источник горизонтальных отступов.
     16px ИЛИ отступ под вырез камеры в ландшафте. */
  --gutter-l: max(16px, env(safe-area-inset-left, 0px));
  --gutter-r: max(16px, env(safe-area-inset-right, 0px));
}

*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  font: 17px/1.55 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Arial, sans-serif;
  color: var(--ink);
  background: #fff;
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
  overflow-wrap: anywhere;
}
img { display: block; max-width: 100%; height: auto; }
a { color: var(--ink); }

/* Заголовки: горизонтальные отступы даёт main, здесь только вертикальные */
h1, h2 { font-weight: 700; line-height: 1.25; margin: 24px 0 12px; }
h1 { font-size: 24px; }
h2 { font-size: 20px; }

.skip { position: absolute; left: -9999px; }
.skip:focus { left: 16px; top: 8px; z-index: 100; background: #fff; padding: 8px; }

/* ══════════════════════════════════════════════════════
   КОНТЕЙНЕР
   main — единственное место, где задан боковой отступ.
   Все дочерние блоки горизонтальных margin/padding НЕ имеют.
   ══════════════════════════════════════════════════════ */
main {
  padding-top: 0;
  padding-bottom: 112px;          /* под фиксированную .cartbar */
  padding-left: var(--gutter-l);
  padding-right: var(--gutter-r);
}

/* Шапка */
.topbar {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: calc(10px + env(safe-area-inset-top, 0px)) var(--gutter-r) 10px var(--gutter-l);
  background: #fff; border-bottom: 1px solid var(--line);
}
.topbar__logo img { height: 32px; width: auto; }
.topbar__cart {
  min-height: var(--tap); display: flex; align-items: center; gap: 8px;
  text-decoration: none; font-weight: 600;
}
.topbar__count {
  min-width: 24px; height: 24px; padding: 0 7px;
  display: inline-flex; align-items: center; justify-content: center;
  background: var(--gray-dark); color: #fff; border-radius: 12px; font-size: 14px;
}

/* ══════════════════════════════════════════════════════
   МЕНЮ КАТЕГОРИЙ (дерево, с отступом по уровню)
   ══════════════════════════════════════════════════════ */
.catmenu { border-bottom: 1px solid var(--line); background: #fff; }
.catmenu > summary {
  list-style: none; min-height: var(--tap);
  padding: 0 var(--gutter-r) 0 var(--gutter-l);
  display: flex; align-items: center; justify-content: space-between;
  font-weight: 600; font-size: 17px; cursor: pointer;
}
.catmenu > summary::-webkit-details-marker { display: none; }
.catmenu > summary::after { content: "▾"; font-size: 14px; color: var(--gray); }
.catmenu[open] > summary::after { content: "▴"; }

.catmenu__list { margin: 0; padding: 0 0 8px; list-style: none; }
.catmenu__item > a {
  display: block; min-height: var(--tap);
  /* --lvl приходит инлайном из шаблона: 0, 1, 2 ... */
  padding: 14px var(--gutter-r) 14px calc(var(--gutter-l) + var(--lvl, 0) * 18px);
  text-decoration: none; border-top: 1px solid #f0f0f0;
}
.catmenu__item[data-level="0"] > a { font-weight: 700; }
.catmenu__item[data-level="1"] > a { font-size: 16px; }
.catmenu__item[data-level="2"] > a { font-size: 15px; color: var(--ink-2); }
.catmenu__item > a.is-active { background: var(--bg-2); font-weight: 700; }

/* Хлебные крошки */
.crumbs {
  display: flex; flex-wrap: wrap; align-items: center; gap: 6px;
  margin: 12px 0 0; font-size: 15px; color: var(--gray);
}
.crumbs a { color: var(--gray); text-decoration: none; }
.crumbs a:last-of-type { color: var(--ink); }

/* Чипсы подкатегорий */
.chips {
  display: flex; flex-wrap: wrap; gap: 8px;
  margin: 12px 0 20px; padding: 0; list-style: none;
}
.chip {
  display: inline-flex; align-items: center;
  min-height: 40px; padding: 0 14px;
  border: 1px solid var(--line); border-radius: 999px;
  background: var(--bg-2);
  font-size: 15px; font-weight: 500; text-decoration: none;
}
.chip:active { background: #ebebeb; }
/* ══════════════════════════════════════════════════════
   СЕТКА И КАРТОЧКИ — единый «рост»
   ══════════════════════════════════════════════════════ */
.grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 20px 12px;
  padding: 0;
  margin: 0 0 32px;
  list-style: none;
  align-items: stretch;         /* все li в ряду одной высоты */
}
.grid > li { display: flex; }    /* чтобы .card мог растянуться */
@media (min-width: 560px) { .grid { grid-template-columns: repeat(3, 1fr); } }
@media (min-width: 860px) { .grid { grid-template-columns: repeat(4, 1fr); } }

.card {
  --title-lines: 2;              /* ← единственная ручка */
  --title-lh: 20px;              /* px, НЕ множитель — см. п.3 */

  display: flex;
  flex-direction: column;
  gap: 6px;
  width: 100%;
  height: 100%;
  min-width: 0;                  /* иначе длинное слово распирает колонку */
}

.card__link {
  display: flex;
  flex-direction: column;
  gap: 6px;
  text-decoration: none;
  color: inherit;
}

/* ── 1. Изображение: квадрат, который нельзя сжать ── */
.card__img {
  position: relative;
  flex: none;                    /* ← ключевое: не сжимается */
  width: 100%;
  aspect-ratio: 1 / 1;
  display: grid;
  place-items: center;
  padding: 8%;
  background: #fff;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  overflow: hidden;
}
.card__img img {
  width: 100%;
  height: 100%;
  object-fit: contain;           /* упаковку не обрезаем */
  object-position: center;
}
.card__noimg {
  width: 56%; height: 56%;
  border-radius: 8px;
  background: var(--bg-2);
}
.card__badge { position: absolute; left: 8px; top: 8px; z-index: 1; }

/* ── 2. Название: ровно N строк у всех ── */
.card__name {
  display: -webkit-box;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: var(--title-lines);
  line-clamp: var(--title-lines);
  height: calc(var(--title-lines) * var(--title-lh));  /* height, не min-height */
  overflow: hidden;
  font-size: 15px;
  line-height: var(--title-lh);
  font-weight: 600;
  font-size-adjust: ex-height 0.52;   /* выравнивает x-height фолбэков */
}

/* ── 3. Цена: одна строка, табличные цифры ── */
.card__prices {
  display: flex;
  align-items: baseline;
  gap: 6px;
  height: 26px;
  overflow: hidden;
  white-space: nowrap;
}
.price {
  font-size: 19px; font-weight: 700;
  font-variant-numeric: tabular-nums;
}
.price__old {
  font-size: 14px; font-weight: 400; color: #8a8a8a;
  text-decoration: line-through;
  font-variant-numeric: tabular-nums;
}

/* ── 4. Кнопки прижаты к низу ── */
.card__actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 6px;
  margin-top: auto;
}
@media (max-width: 359px) { .card__actions { grid-template-columns: 1fr; } }

/* Бейджи — одной высоты независимо от текста */
.badge {
  display: inline-flex; align-items: center; justify-content: center;
  height: 22px; padding: 0 8px;
  border-radius: 6px;
  font-size: 12px; font-weight: 600; line-height: 1; white-space: nowrap;
}
.badge--sale { background: var(--ink); color: #fff; }
.badge--hit  { background: #e9e9e9; color: var(--ink); }

.card__name .e,
h1 .e, h2 .e {
  font-family: "Apple Color Emoji", "Segoe UI Emoji",
               "Noto Color Emoji", sans-serif;
  font-size: 0.85em;
  line-height: 0;            /* убирает вклад глифа в высоту строки */
  vertical-align: -0.08em;   /* чуть опустить к базовой линии */
}

/* ══════════════════════════════════════════════════════
   КНОПКИ
   ══════════════════════════════════════════════════════ */
.btn {
  display: flex; align-items: center; justify-content: center;
  min-height: var(--tap); padding: 0 20px; width: 100%;
  border: 1px solid var(--gray-dark); border-radius: var(--radius);
  background: var(--gray-dark); color: #fff;
  /* шорткод font с inherit невалиден — только longhand */
  font-family: inherit; font-size: 17px; font-weight: 600; line-height: 1.2;
  text-align: center; text-decoration: none;
  cursor: pointer; -webkit-appearance: none; appearance: none;
}
.btn--gray { background: var(--gray); border-color: var(--gray); }
.btn--outline { background: #fff; color: var(--ink); border-color: var(--ink); }
.btn:active { transform: translateY(1px); }
.btn[disabled] { background: #b9b9b9; border-color: #b9b9b9; }

/* компактная кнопка для карточки каталога */
.btn--sm {
  min-height: var(--tap-sm); padding: 0 8px;
  font-size: 14px; border-radius: 10px;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.btn--sm[disabled] { color: #fff; }

/* на самых узких экранах кнопки в карточке — в столбик */
@media (max-width: 359px) {
  .card__actions { grid-template-columns: 1fr; }
}

.btn__row { display: grid; gap: 10px; margin: 16px 0; }
@media (prefers-reduced-motion: reduce) { .btn:active { transform: none; } }

/* ══════════════════════════════════════════════════════
   ФОРМЫ
   ══════════════════════════════════════════════════════ */
.field { display: block; margin: 0 0 16px; }
.field > span { display: block; margin-bottom: 6px; font-size: 15px; color: var(--ink-2); }

/* ВАЖНО: только текстовые поля. Чекбоксы/радио сюда не попадают. */
.field input:not([type="checkbox"]):not([type="radio"]),
.field textarea,
.field select {
  width: 100%; min-height: var(--tap); padding: 12px 14px;
  font-family: inherit; font-size: 17px; line-height: 1.4; color: var(--ink);
  background-color: #fff;
  border: 1px solid #b9b9b9; border-radius: var(--radius);
  -webkit-appearance: none; appearance: none;
}
.field textarea { min-height: 96px; resize: vertical; }
.field input:focus, .field textarea:focus, .field select:focus {
  outline: 2px solid var(--ink); outline-offset: 1px;
}

/* Select: своя стрелка + серый цвет у пустого значения */
.field select {
  padding-right: 46px;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8'%3E%3Cpath d='M1 1.5 6 6.5 11 1.5' fill='none' stroke='%236f6f6f' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 16px center;
  background-size: 12px 8px;
  cursor: pointer;
}
/* работает при <select required> и первой пустой <option value=""> */
.field select:required:invalid { color: var(--gray); }
.field select option { color: var(--ink); }

/* Чекбоксы и радио — нативные, крупные, без appearance:none */
.check {
  display: flex; align-items: flex-start; gap: 12px;
  min-height: var(--tap-sm); margin: 0 0 12px; padding: 8px 0;
  font-size: 16px; line-height: 1.4; cursor: pointer;
}
.check input[type="checkbox"],
.check input[type="radio"] {
  flex: 0 0 auto;
  width: 24px; height: 24px; margin: 0;
  accent-color: var(--gray-dark);
  cursor: pointer;
}

/* Кастомный вариант, если нативный вид не устраивает */
.check--custom { position: relative; }
.check--custom input {
  position: absolute; left: 0; top: 8px;
  width: 24px; height: 24px; margin: 0; opacity: 0;
}
.check--custom .box {
  flex: 0 0 auto; width: 24px; height: 24px;
  display: grid; place-items: center;
  border: 2px solid #b9b9b9; border-radius: 6px; background: #fff;
}
.check--custom .box::after {
  content: ""; width: 12px; height: 7px;
  border-left: 2px solid #fff; border-bottom: 2px solid #fff;
  transform: rotate(-45deg) translate(1px, -1px) scale(0);
  transition: transform .12s ease-out;
}
.check--custom input:checked + .box { background: var(--gray-dark); border-color: var(--gray-dark); }
.check--custom input:checked + .box::after { transform: rotate(-45deg) translate(1px, -1px) scale(1); }
.check--custom input:focus-visible + .box { outline: 2px solid var(--ink); outline-offset: 2px; }
.check--custom input[type="radio"] + .box { border-radius: 50%; }
.check--custom input[type="radio"] + .box::after {
  width: 10px; height: 10px; border: 0; border-radius: 50%;
  background: #fff; transform: scale(0);
}
.check--custom input[type="radio"]:checked + .box::after { transform: scale(1); }
@media (prefers-reduced-motion: reduce) {
  .check--custom .box::after { transition: none; }
}

.hint { font-size: 15px; color: var(--ink-2); margin: 4px 0 0; }
.error { font-size: 15px; color: #a11; margin: 4px 0 0; }

/* Таблица оптовых скидок */
.tiers { width: 100%; margin: 0 0 16px; border-collapse: collapse; font-size: 16px; }
.tiers caption { text-align: left; font-weight: 600; padding-bottom: 8px; }
.tiers th, .tiers td { padding: 10px 0; border-bottom: 1px solid var(--line); text-align: left; }
.tiers td:last-child { text-align: right; white-space: nowrap; font-weight: 600; }

/* Пагинация и пустой результат */
.pager {
  display: flex; align-items: center; gap: 12px;
  margin: 8px 0 24px;
}
.pager .btn { width: auto; flex: 0 0 auto; min-width: 110px; padding: 0 16px; font-size: 16px; }
.pager .hint { flex: 1; margin: 0; text-align: center; }

.empty {
  grid-column: 1 / -1;
  padding: 32px 0; text-align: center;
  color: var(--gray); list-style: none;
}

/* Нижняя панель */
.cartbar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 30;
  display: flex; align-items: center; gap: 12px;
  padding: 10px var(--gutter-r) calc(10px + env(safe-area-inset-bottom, 0px)) var(--gutter-l);
  background: #fff; border-top: 1px solid var(--line);
}
.cartbar__sum { font-weight: 700; font-size: 18px; }
.cartbar .btn { width: auto; flex: 1; }

.footer {
  padding: 24px var(--gutter-r) calc(32px + env(safe-area-inset-bottom, 0px)) var(--gutter-l);
  border-top: 1px solid var(--line); font-size: 15px; color: var(--ink-2);
}
.footer p { margin: 0 0 6px; }