/* Мини-апп всегда светлый по требованию заказчика, независимо от темы
   Telegram у пользователя. Цвета фиксированные, без какой-либо привязки
   к теме клиента — так надёжнее и не зависит от того, что именно прислал
   конкретный клиент Telegram.
   --button/--button-light/--button-dark — единственное, что реально
   настраивается по магазинам (см. db/settings.py:get_brand_color,
   main.py:_brand_theme_vars, templates/base.html — там эти три
   переменные подменяются инлайновым <style> под конкретный магазин).
   Значения ниже — дефолт для случая, когда переопределения нет. */
:root {
  --bg: #ffffff;
  --text: #1c1c28;
  --hint: #8a8a99;
  --link: #2a7de1;
  --button: #6c5ce7;
  --button-light: rgb(240, 239, 253);
  --button-dark: rgb(89, 75, 189);
  --button-text: #ffffff;
  --secondary-bg: #f4f3fa;
  --card-bg: #ffffff;
  --border: #ececf3;
  --danger: #e0483e;
  --shadow-sm: 0 2px 10px rgba(28, 28, 40, 0.06);
  --shadow-md: 0 6px 20px rgba(28, 28, 40, 0.10);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  font-size: 15px;
  overflow-x: hidden;
  max-width: 100vw;
}

#app {
  display: flex;
  flex-direction: column;
  min-height: 100vh;
  padding-bottom: 68px;
}

header.topbar {
  padding: 14px 16px;
  font-weight: 700;
  font-size: 1.1em;
  border-bottom: 1px solid var(--border);
  background: var(--bg);
}
.shop-logo {
  width: 26px;
  height: 26px;
  border-radius: 8px;
  object-fit: cover;
  flex: none;
  background: var(--secondary-bg);
}

main {
  flex: 1;
  padding: 12px;
}

.search-row {
  display: flex;
  gap: 8px;
  margin-bottom: 10px;
}
.search-row input { flex: 1; min-width: 0; }
.search-row button {
  flex: none;
  padding: 9px 12px;
}

.fav-heart {
  position: absolute;
  top: 8px;
  right: 8px;
  background: rgba(255, 255, 255, 0.92);
  border: none;
  border-radius: 999px;
  width: 30px;
  height: 30px;
  padding: 0;
  font-size: 0.95em;
  line-height: 1;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: var(--shadow-sm);
  transition: transform 0.1s;
}
.fav-heart:active { transform: scale(0.9); }

input, textarea, select {
  width: 100%;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: 12px;
  font-size: 0.95em;
  background: var(--secondary-bg);
  color: var(--text);
  transition: box-shadow 0.15s, border-color 0.15s;
}
input:focus, textarea:focus, select:focus {
  outline: none;
  border-color: var(--button);
  box-shadow: 0 0 0 3px var(--button-light);
  background: var(--card-bg);
}
input::placeholder, textarea::placeholder { color: var(--hint); }

/* Чекбоксы/радио — не обычные текстовые поля: общее правило выше даёт им
   рамку, фон и большой внутренний отступ, из-за чего в списке (например,
   категории товара) они превращаются в слипшиеся квадраты и мешают попасть
   тапом по нужному пункту. Возвращаем нативный вид. */
input[type="checkbox"], input[type="radio"] {
  width: auto;
  padding: 0;
  border: none;
  border-radius: 0;
  background: none;
}

.categories {
  display: flex;
  gap: 8px;
  overflow-x: auto;
  padding-bottom: 8px;
  margin-bottom: 10px;
}
.categories .chip {
  flex: none;
  padding: 7px 14px;
  border-radius: 999px;
  background: var(--secondary-bg);
  color: var(--text);
  font-size: 0.85em;
  font-weight: 500;
  cursor: pointer;
  white-space: nowrap;
  transition: transform 0.1s;
}
.categories .chip:active { transform: scale(0.96); }
.categories .chip.active {
  background: var(--button);
  color: var(--button-text);
  box-shadow: var(--shadow-sm);
}
.categories .chip.muted {
  opacity: 0.5;
}

.product-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}

.card {
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: 18px;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  box-shadow: var(--shadow-sm);
}

.card img {
  width: 100%;
  aspect-ratio: 1;
  object-fit: cover;
  background: var(--secondary-bg);
}

.card .body {
  padding: 10px 12px 12px;
  display: flex;
  flex-direction: column;
  gap: 4px;
  flex: 1;
}

/* Ровно 2 строки всегда — иначе у карточек с более длинным названием тело
   вырастало сильнее, чем у соседей, и сетка 2×N выглядела неровной (разная
   высота карточек в одном ряду). min-height резервирует место коротким
   названиям, line-clamp обрезает длинные многоточием вместо переполнения. */
.card .title {
  font-size: 0.9em;
  font-weight: 600;
  line-height: 1.3;
  min-height: 2.6em;
  max-height: 2.6em;
  overflow: hidden;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
}

.card .price {
  font-weight: 700;
  color: var(--button-dark);
}

/* Плавающая кнопка "+" поверх фото товара (вместо текстовой кнопки под
   карточкой) — компактнее на маленьких карточках сетки 2×N и привычнее
   по паттерну для мобильной e-commerce вёрстки. */
.card-add-wrap {
  position: absolute;
  right: 8px;
  bottom: 8px;
}
.card-add-btn {
  width: 34px;
  height: 34px;
  padding: 0;
  border-radius: 50%;
  font-size: 1.3em;
  line-height: 1;
  box-shadow: var(--shadow-md);
}
.card-add-btn:disabled {
  background: var(--secondary-bg);
  color: var(--hint);
  box-shadow: none;
}
.card-out-of-stock img { filter: grayscale(0.5); opacity: 0.55; }
.out-of-stock-label {
  position: absolute;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
  background: rgba(28, 28, 40, 0.75);
  color: #fff;
  padding: 4px 10px;
  border-radius: 999px;
  font-size: 0.72em;
  font-weight: 600;
  white-space: nowrap;
}
.qty-control-float {
  background: var(--card-bg);
  border-radius: 999px;
  padding: 3px 4px;
  gap: 4px;
  box-shadow: var(--shadow-md);
}
.qty-control-float button {
  width: 26px;
  height: 26px;
}

.rating {
  font-size: 0.8em;
}

.stock-line {
  font-size: 0.78em;
}

@keyframes skeleton-pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.5; }
}
.skeleton-block, .skeleton-line {
  background: var(--secondary-bg);
  animation: skeleton-pulse 1.2s ease-in-out infinite;
}
.skeleton-block {
  width: 100%;
  aspect-ratio: 1;
}
.skeleton-line {
  height: 0.9em;
  border-radius: 4px;
  margin: 6px 0;
}

.badge-new {
  position: absolute;
  margin: 8px;
  padding: 3px 9px;
  background: var(--button);
  color: var(--button-text);
  border-radius: 999px;
  font-size: 0.72em;
  font-weight: 600;
  box-shadow: var(--shadow-sm);
}

.card-media { position: relative; }

button {
  border: none;
  border-radius: 12px;
  padding: 10px 16px;
  background: var(--button);
  color: var(--button-text);
  font-size: 0.95em;
  font-weight: 600;
  cursor: pointer;
  transition: transform 0.1s, opacity 0.1s;
}
button:active:not(:disabled) { transform: scale(0.97); }
button.secondary {
  background: var(--secondary-bg);
  color: var(--text);
}
button.danger {
  background: var(--danger);
  color: #fff;
}
button:disabled {
  opacity: 0.5;
  cursor: default;
}
button.small {
  padding: 6px 12px;
  font-size: 0.85em;
  border-radius: 10px;
}

.qty-control {
  display: flex;
  align-items: center;
  gap: 8px;
}
.qty-control button {
  width: 28px;
  height: 28px;
  padding: 0;
  line-height: 1;
  border-radius: 50%;
}
.qty-control span { font-weight: 600; min-width: 1.2em; text-align: center; }

.cart-item, .order-row, .tx-row {
  display: flex;
  gap: 12px;
  padding: 12px 0;
  border-bottom: 1px solid var(--border);
  align-items: center;
}
.cart-item img {
  width: 60px;
  height: 60px;
  border-radius: 12px;
  object-fit: cover;
  background: var(--secondary-bg);
}
.cart-item .info { flex: 1; }

.summary-row {
  display: flex;
  justify-content: space-between;
  padding: 4px 0;
}
.summary-row.total {
  font-weight: 700;
  font-size: 1.05em;
  border-top: 1px solid var(--border);
  margin-top: 6px;
  padding-top: 8px;
}

.muted { color: var(--hint); }

.status-pill {
  display: inline-block;
  padding: 3px 10px;
  border-radius: 999px;
  font-size: 0.8em;
  font-weight: 600;
  background: var(--secondary-bg);
}
.status-pill.confirmed { background: #dcf5df; color: #1a7431; }
.status-pill.cancelled { background: #fbe0de; color: var(--danger); }

.empty-state {
  text-align: center;
  color: var(--hint);
  padding: 40px 20px;
}

nav.bottom-nav {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  display: flex;
  background: var(--card-bg);
  box-shadow: 0 -2px 16px rgba(28, 28, 40, 0.08);
  border-radius: 20px 20px 0 0;
  padding: 8px 6px max(8px, env(safe-area-inset-bottom));
  gap: 4px;
}
nav.bottom-nav .nav-item {
  flex: 1;
  text-align: center;
  font-size: 0.75em;
  font-weight: 500;
  color: var(--hint);
  cursor: pointer;
  padding: 6px 0;
  border-radius: 14px;
  position: relative;
  transition: background 0.15s, color 0.15s;
}
nav.bottom-nav .nav-item.active {
  color: var(--button-dark);
  font-weight: 700;
  background: var(--button-light);
}
nav.bottom-nav .nav-icon { font-size: 1.3em; display: block; }
.cart-badge {
  position: absolute;
  top: 0;
  right: 22%;
  background: var(--danger);
  color: #fff;
  border-radius: 999px;
  font-size: 0.7em;
  padding: 0 5px;
  box-shadow: 0 0 0 2px var(--card-bg);
}

.toast {
  position: fixed;
  bottom: 84px;
  left: 50%;
  transform: translateX(-50%);
  background: var(--text);
  color: var(--bg);
  padding: 10px 18px;
  border-radius: 999px;
  font-size: 0.85em;
  box-shadow: var(--shadow-md);
  opacity: 0;
  transition: opacity 0.2s;
  pointer-events: none;
  z-index: 50;
}
.toast.show { opacity: 0.95; }

form .field { margin-bottom: 10px; }
form label { display: block; font-size: 0.85em; margin-bottom: 4px; color: var(--hint); }

.admin-table {
  width: 100%;
  max-width: 100%;
  table-layout: fixed;
  border-collapse: collapse;
  border-radius: 14px;
  overflow: hidden;
  box-shadow: var(--shadow-sm);
}
.admin-table th, .admin-table td {
  padding: 9px 8px;
  border-bottom: 1px solid var(--border);
  text-align: left;
  font-size: 0.85em;
  overflow: hidden;
  text-overflow: ellipsis;
  word-break: break-word;
}
.admin-table th {
  background: var(--secondary-bg);
  color: var(--hint);
  font-weight: 600;
  font-size: 0.8em;
  text-transform: uppercase;
  letter-spacing: 0.02em;
}
.admin-table tbody tr:last-child td,
.admin-table tr:last-child td { border-bottom: none; }
.admin-table tr:active td { background: var(--secondary-bg); }
/* Название — единственная колонка, которой реально нужна ширина, остальные
   (чекбокс/фото/цена/остаток/кнопки) — фиксированной ширины под содержимое,
   чтобы таблица никогда не растягивала страницу вбок. */
.admin-table-compact th:nth-child(1), .admin-table-compact td:nth-child(1) { width: 24px; }
.admin-table-compact th:nth-child(2), .admin-table-compact td:nth-child(2) { width: 38px; }
.admin-table-compact th:nth-child(4), .admin-table-compact td:nth-child(4) { width: 22%; }
.admin-table-compact th:nth-child(5), .admin-table-compact td:nth-child(5) { width: 15%; }
.admin-table-compact th:nth-child(6), .admin-table-compact td:nth-child(6) { width: 88px; }

/* Таблица «Остатки» (routers/admin.py:/stock) — своя 4-колоночная
   раскладка (название/цена/остаток/статус), admin-table-compact сюда не
   подходит: его nth-child-правила рассчитаны на 6-колоночный список
   товаров и сжимали бы «Название» до 24px. */
.stock-table th:nth-child(2), .stock-table td:nth-child(2) { width: 78px; }
.stock-table th:nth-child(3), .stock-table td:nth-child(3) { width: 84px; }
.stock-table th:nth-child(4), .stock-table td:nth-child(4) { width: 64px; }

/* Таблица «Категории» — 3 кнопки действий (✏️/показать-скрыть/🗑) в узкой
   4-й колонке раньше переносились на 2-3 строки (flex-wrap на
   .row-actions). Даём колонке с кнопками фиксированную ширину под
   реальный контент вместо равной 1/4 от .admin-table по умолчанию. */
.categories-table th:nth-child(1), .categories-table td:nth-child(1) { width: 52px; }
.categories-table th:nth-child(3), .categories-table td:nth-child(3) { width: 58px; }
.categories-table th:nth-child(4), .categories-table td:nth-child(4) { width: 134px; }

.discounts-table th:nth-child(3), .discounts-table td:nth-child(3) { width: 56px; }
.discounts-table th:nth-child(4), .discounts-table td:nth-child(4) { width: 64px; }
.discounts-table th:nth-child(5), .discounts-table td:nth-child(5) { width: 96px; }

.row-actions {
  display: flex;
  gap: 3px;
  flex-wrap: nowrap;
}
.row-actions button {
  padding: 4px 5px;
  min-width: 0;
}

.row-hidden {
  opacity: 0.45;
}

/* Раньше .tabs переносил 9 вкладок в 3 неровных ряда (flex-wrap) — на
   телефоне это треть экрана одних только кнопок ещё до всякого контента.
   Прокрутка в одну строку — стандартный паттерн для табов в мобильных
   мини-аппах (как верхние вкладки в Instagram/Telegram) вместо переноса.
   Скроллбар спрятан, сама прокрутка остаётся полностью рабочей — свайпом
   на телефоне, колесом мыши на компьютере (см. ui.js:enhanceTabsScroll).
   Явных стрелок нет (визуально мешали) — вместо них выбранная вкладка
   сама центрируется в строке (см. ui.js:centerTabInScroll), открывая
   соседей по обе стороны. */
.tabs-scroll {
  display: flex;
  align-items: stretch;
  overflow-x: auto;
  overflow-y: hidden;
  margin: 0 -12px 12px;
  padding: 0 12px;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: none;
}
.tabs-scroll::-webkit-scrollbar { display: none; }
.tabs {
  display: flex;
  gap: 6px;
  flex-wrap: nowrap;
  flex: none;
  align-items: center;
  width: max-content;
}
.tabs .tab {
  padding: 7px 14px;
  border-radius: 999px;
  background: var(--secondary-bg);
  cursor: pointer;
  font-size: 0.85em;
  font-weight: 500;
  white-space: nowrap;
  flex: none;
}
.tabs .tab.active {
  background: var(--button);
  color: var(--button-text);
  font-weight: 600;
  box-shadow: var(--shadow-sm);
}

/* Скругление углов — на неподвижной обёртке, а не на самой прокручиваемой
   .gallery: overflow:hidden (нужен для border-radius) и overflow-x:auto
   (нужен для скролла) — это одно и то же CSS-свойство "overflow" по двум
   осям, второе объявление всегда перебивало первое, и прокрутка фото
   молча переставала работать даже при нескольких картинках. Отступ и
   радиус здесь завязаны на padding/border-radius .modal-sheet — меняешь
   один, меняй и другой. */
.gallery-wrap {
  margin: -18px -18px 0;
  border-radius: 22px 22px 0 0;
  overflow: hidden;
}
.gallery {
  display: flex;
  overflow-x: auto;
  overflow-y: hidden;
  scroll-snap-type: x mandatory;
  gap: 0;
}
.gallery img {
  flex: none;
  width: 100%;
  aspect-ratio: 1;
  object-fit: cover;
  scroll-snap-align: start;
  background: var(--secondary-bg);
}

.gallery-manager {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin: 8px 0;
}
.gallery-manager .thumb {
  position: relative;
  width: 64px;
  height: 64px;
}
.gallery-manager .thumb img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  border-radius: 8px;
  border: 1px solid var(--border);
}
.gallery-manager .thumb .remove {
  position: absolute;
  top: -6px;
  right: -6px;
  width: 20px;
  height: 20px;
  border-radius: 50%;
  background: var(--danger);
  color: #fff;
  border: none;
  font-size: 0.7em;
  line-height: 1;
  cursor: pointer;
  padding: 0;
}
.gallery-manager .add-tile {
  width: 64px;
  height: 64px;
  border-radius: 8px;
  border: 1px dashed var(--border);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.4em;
  color: var(--hint);
  cursor: pointer;
  background: none;
}

.variant-manager {
  margin: 10px 0;
  padding: 10px;
  border: 1px solid var(--border);
  border-radius: 10px;
}
.variant-row {
  display: flex;
  gap: 8px;
  align-items: center;
  min-width: 0;
}
.variant-row input { min-width: 0; }
.variant-manager .variant-row {
  padding: 6px 0;
  border-bottom: 1px solid var(--border);
  font-size: 0.9em;
}
.variant-manager .variant-row:last-child { border-bottom: none; }
.variant-manager .variant-row .label { flex: 1; min-width: 0; overflow-wrap: break-word; }

.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(20, 18, 35, 0.45);
  display: flex;
  align-items: flex-end;
  justify-content: center;
  z-index: 100;
}
.modal-sheet {
  background: var(--bg);
  width: 100%;
  max-width: 480px;
  border-radius: 22px 22px 0 0;
  padding: 18px;
  max-height: 88vh;
  overflow-y: auto;
  box-shadow: 0 -8px 30px rgba(20, 18, 35, 0.18);
  position: relative;
}
/* Полоска-ручка сверху шторки — привычный визуальный намёк, что это
   можно закрыть свайпом/тапом по фону, даже без реальной drag-логики. */
.modal-sheet::before {
  content: "";
  position: absolute;
  top: 8px;
  left: 50%;
  transform: translateX(-50%);
  width: 36px;
  height: 4px;
  border-radius: 999px;
  background: var(--border);
}
