/* Цвета берутся из темы Telegram (переменные --tg-theme-* ставит telegram-web-app.js), запасные — для браузера. */
:root {
  --bg: var(--tg-theme-bg-color, #ffffff);
  --surface: var(--tg-theme-secondary-bg-color, #f1f2f5);
  --text: var(--tg-theme-text-color, #16181d);
  --hint: var(--tg-theme-hint-color, #6f7680);
  --accent: var(--tg-theme-button-color, #2f7de1);
  --accent-text: var(--tg-theme-button-text-color, #ffffff);
  --link: var(--tg-theme-link-color, #2f7de1);
  --separator: var(--tg-theme-section-separator-color, rgba(127, 127, 127, 0.18));
  --danger: var(--tg-theme-destructive-text-color, #d9473f);
  --radius: 14px;
  --radius-small: 10px;
  --gap: 12px;
  --pad: 16px;
  --text-xs: 13px;
  --text-s: 15px;
  --text-m: 17px;
  --text-l: 28px;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-tg]) {
    --bg: #17191d;
    --surface: #23262c;
    --text: #eef0f3;
    --hint: #8d949e;
    --accent: #4b93ee;
    --link: #6aa8f5;
  }
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 400 var(--text-s)/1.4 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  -webkit-tap-highlight-color: transparent;
}

main {
  max-width: 560px;
  margin: 0 auto;
  padding: var(--pad) var(--pad) calc(var(--pad) + env(safe-area-inset-bottom));
}

button {
  font: inherit;
  color: inherit;
  background: none;
  border: 0;
  padding: 0;
  cursor: pointer;
}

svg.icon {
  width: 20px;
  height: 20px;
  flex: none;
  fill: none;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.status {
  color: var(--hint);
  text-align: center;
  padding: 48px var(--pad);
}

.message {
  text-align: center;
  padding: 48px var(--pad);
}

.message h1 {
  font-size: var(--text-m);
  margin: 0 0 8px;
}

.message p {
  color: var(--hint);
  margin: 0 0 20px;
}

.primary {
  background: var(--accent);
  color: var(--accent-text);
  border-radius: var(--radius-small);
  padding: 12px 20px;
  font-weight: 600;
}

.search {
  position: sticky;
  top: 0;
  z-index: 1;
  display: flex;
  align-items: center;
  gap: 8px;
  margin: calc(-1 * var(--pad)) calc(-1 * var(--pad)) var(--gap);
  padding: var(--pad);
  background: var(--bg);
}

.search label {
  flex: 1;
  display: flex;
  align-items: center;
  gap: 8px;
  background: var(--surface);
  border-radius: var(--radius-small);
  padding: 0 12px;
  color: var(--hint);
}

.search input {
  flex: 1;
  min-width: 0;
  border: 0;
  outline: 0;
  background: transparent;
  color: var(--text);
  font: inherit;
  font-size: var(--text-m);
  padding: 11px 0;
}

.section-title {
  margin: 20px 4px 8px;
  font-size: var(--text-xs);
  font-weight: 600;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--hint);
}

.list {
  background: var(--surface);
  border-radius: var(--radius);
  overflow: hidden;
}

.row {
  width: 100%;
  display: flex;
  align-items: center;
  gap: var(--gap);
  padding: 13px var(--pad);
  text-align: left;
  border-top: 1px solid var(--separator);
}

.row:first-child { border-top: 0; }
.row:active { background: var(--separator); }

.row .title {
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: var(--text-m);
}

.row .meta {
  color: var(--hint);
  font-size: var(--text-xs);
  white-space: nowrap;
}

.row .lead { color: var(--link); }
.row .chevron { color: var(--hint); }
.row .star { color: #f2b01e; }

.empty {
  color: var(--hint);
  padding: 13px var(--pad);
}

.crumbs {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 4px 6px;
  margin: 0 4px var(--gap);
  font-size: var(--text-xs);
  color: var(--hint);
}

.crumbs button { color: var(--link); }
.crumbs .here { color: var(--text); font-weight: 600; }

.cell-head {
  margin: 4px 4px var(--gap);
}

.cell-head h1 {
  margin: 0;
  font-size: var(--text-l);
  line-height: 1.15;
  overflow-wrap: anywhere;
}

.cell-head .note {
  color: var(--danger);
}

.cell-head p {
  margin: 4px 0 0;
  color: var(--hint);
  font-size: var(--text-xs);
}

/* Белая подложка в любой теме: на тёмном фоне сканер штрихкод не прочитает. */
.barcode {
  background: #ffffff;
  border-radius: var(--radius);
  padding: 12px 6px;
}

.barcode svg {
  display: block;
  width: 100%;
  height: auto;
}

.actions {
  display: flex;
  gap: 8px;
  margin-top: var(--gap);
}

.actions button {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  min-height: 44px;
  padding: 8px;
  background: var(--surface);
  border-radius: var(--radius-small);
  font-size: var(--text-s);
}

.actions button[disabled] { opacity: 0.35; cursor: default; }
.actions .favorite[aria-pressed="true"] { color: #f2b01e; }
.actions .favorite[aria-pressed="true"] svg { fill: currentColor; }

.duplicate { margin-top: 20px; }

.duplicate h2 {
  margin: 0 4px 8px;
  font-size: var(--text-xs);
  font-weight: 600;
  color: var(--hint);
}

.more {
  margin: 8px 4px 0;
  color: var(--hint);
  font-size: var(--text-xs);
}

/* Главное меню: широкие горизонтальные карточки одна под другой. */
.tiles {
  display: grid;
  gap: var(--gap);
}

.tile {
  display: flex;
  align-items: center;
  gap: var(--gap);
  width: 100%;
  padding: var(--pad);
  background: var(--surface);
  border-radius: var(--radius);
  text-align: left;
}

.tile:active { background: var(--separator); }
.tile .tile-icon { width: 28px; height: 28px; color: var(--link); }
.tile .chevron { color: var(--hint); }

.tile-text {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 2px;
}
.tile-title { font-size: var(--text-m); font-weight: 600; }
.tile-hint { font-size: var(--text-xs); color: var(--hint); }

.toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--gap);
  margin: 0 4px var(--gap);
}

.toolbar p { margin: 0; }

.refresh {
  flex: none;
  color: var(--link);
  font-size: var(--text-s);
  padding: 6px 0;
}

.warning {
  color: var(--danger);
  font-size: var(--text-xs);
}

.step { margin-top: 20px; }

.step h2 {
  margin: 0 4px 8px;
  font-size: var(--text-s);
  font-weight: 600;
}

.position-wrap + .position-wrap { border-top: 1px solid var(--separator); }
.position-wrap .row { border-top: 0; }
.position[aria-expanded="true"] .chevron { transform: rotate(90deg); }

.position-body {
  padding: 0 var(--pad) var(--pad);
}

.position-body .step:first-child { margin-top: 4px; }

.chips {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 8px;
}

.chip {
  padding: 6px 10px;
  border-radius: 999px;
  background: var(--bg);
  border: 1px solid var(--separator);
  font-size: var(--text-xs);
}

.chip[aria-pressed="true"] {
  background: var(--accent);
  color: var(--accent-text);
  border-color: var(--accent);
}

.manual {
  margin: 0;
  padding: 14px var(--pad);
  background: var(--surface);
  border-radius: var(--radius);
  color: var(--hint);
}

/* Фото товара: белая подложка, потому что у фото М.Видео белый фон. */
.thumb {
  width: 40px;
  height: 40px;
  flex: none;
  object-fit: contain;
  background: #ffffff;
  border-radius: 8px;
}

.photo {
  display: block;
  width: 100%;
  max-height: 200px;
  object-fit: contain;
  background: #ffffff;
  border-radius: var(--radius);
  padding: 8px;
  margin-top: 4px;
}

.product-form {
  display: flex;
  gap: 8px;
  margin-bottom: var(--gap);
}

.field {
  flex: 1;
  min-width: 0;
  display: flex;
  align-items: center;
  gap: 8px;
  background: var(--surface);
  border-radius: var(--radius-small);
  padding: 0 12px;
  color: var(--hint);
}

.field input {
  flex: 1;
  min-width: 0;
  border: 0;
  outline: 0;
  background: transparent;
  color: var(--text);
  font: inherit;
  font-size: var(--text-m);
  padding: 11px 0;
}

.primary[disabled] { opacity: 0.5; }

/* Названия товаров длинные: заголовок мельче, чем имя полки. */
.product-head h1 {
  font-size: 20px;
  line-height: 1.25;
}
