/* Мини-апп закупок — «ночная кухня»: стальной графит + шафран.
   Токены на :root, тёмная тема по умолчанию (смены закрываются ночью),
   светлая — через prefers-color-scheme и data-theme (тема Телеграма). */

:root {
  --bg: #14171c;
  --card: #1d2127;
  --card2: #232830;
  --line: #2e3542;
  --text: #edeef0;
  --muted: #98a1af;
  --accent: #e8a13c;
  --accent-ink: #1a1204;
  --danger: #e4574d;
  --ok: #3fa96c;
  --warn: #d9a036;
  --shadow: 0 8px 28px rgba(0, 0, 0, .45);
}
@media (prefers-color-scheme: light) {
  :root {
    --bg: #f3f4f2;
    --card: #ffffff;
    --card2: #f7f8f7;
    --line: #dfe2e7;
    --text: #1c2026;
    --muted: #5d6674;
    --accent: #b87a16;
    --accent-ink: #ffffff;
    --danger: #c4443b;
    --ok: #2e8b57;
    --warn: #a06d10;
    --shadow: 0 8px 24px rgba(25, 30, 40, .12);
  }
}
:root[data-theme="light"] {
  --bg: #f3f4f2; --card: #ffffff; --card2: #f7f8f7; --line: #dfe2e7;
  --text: #1c2026; --muted: #5d6674; --accent: #b87a16; --accent-ink: #ffffff;
  --danger: #c4443b; --ok: #2e8b57; --warn: #a06d10;
  --shadow: 0 8px 24px rgba(25, 30, 40, .12);
}
:root[data-theme="dark"] {
  --bg: #14171c; --card: #1d2127; --card2: #232830; --line: #2e3542;
  --text: #edeef0; --muted: #98a1af; --accent: #e8a13c; --accent-ink: #1a1204;
  --danger: #e4574d; --ok: #3fa96c; --warn: #d9a036;
  --shadow: 0 8px 28px rgba(0, 0, 0, .45);
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font: 15px/1.45 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto,
        "Helvetica Neue", Arial, sans-serif;
  padding-bottom: 84px;
}
button { font: inherit; color: inherit; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

/* ── шапка ─────────────────────────────────────────────────────────── */
header#top {
  position: sticky; top: 0; z-index: 30;
  background: var(--bg);
  border-bottom: 1px solid var(--line);
  padding: 10px 14px 0;
}
.head-row { display: flex; align-items: center; gap: 12px; }
.brand { flex: 1; min-width: 0; }
.brand-title { font-size: 17px; font-weight: 700; letter-spacing: -.01em; }
.meta { font-size: 11.5px; color: var(--muted); margin-top: 1px;
        white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
select.branch {
  appearance: none; -webkit-appearance: none;
  background: var(--card2); color: var(--text);
  border: 1px solid var(--line); border-radius: 10px;
  padding: 8px 12px; font-size: 14px; font-weight: 600; max-width: 46%;
}
.search-wrap { position: relative; margin-top: 10px; }
#search {
  width: 100%; padding: 10px 12px;
  background: var(--card); color: var(--text);
  border: 1px solid var(--line); border-radius: 12px; font-size: 15px;
}
#search::placeholder { color: var(--muted); }
.results {
  position: absolute; left: 0; right: 0; top: calc(100% + 6px); z-index: 40;
  background: var(--card); border: 1px solid var(--line); border-radius: 12px;
  box-shadow: var(--shadow); max-height: 46vh; overflow-y: auto;
}
.results .found {
  display: block; width: 100%; text-align: left;
  padding: 11px 14px; background: none; border: 0;
  border-bottom: 1px solid var(--line); cursor: pointer;
}
.results .found:last-child { border-bottom: 0; }
.results .found:active { background: var(--card2); }
.results .found .found-sub { display: block; font-size: 12px; color: var(--muted); }
.results .hint { padding: 11px 14px; }

/* ── вкладки цехов ─────────────────────────────────────────────────── */
.tabs { display: flex; gap: 6px; padding: 10px 0; }
.tab {
  flex: 1; border: 1px solid var(--line); background: var(--card);
  border-radius: 10px; padding: 8px 6px; cursor: pointer;
  font-size: 14px; font-weight: 600; color: var(--muted);
  transition: background .12s, color .12s, border-color .12s;
}
.tab .n {
  font-weight: 700; font-size: 12px; margin-left: 5px;
  font-variant-numeric: tabular-nums; opacity: .8;
}
.tab.active {
  background: var(--accent); border-color: var(--accent);
  color: var(--accent-ink);
}
.tab .alarm { color: var(--danger); margin-left: 4px; font-weight: 700; }
.tab.active .alarm { color: inherit; }

/* ── лента категорий ───────────────────────────────────────────────── */
.cats {
  display: flex; gap: 6px; overflow-x: auto; padding: 0 0 10px;
  scrollbar-width: none; -webkit-overflow-scrolling: touch;
}
.cats::-webkit-scrollbar { display: none; }
.chip {
  flex: 0 0 auto; border: 1px solid var(--line); background: var(--card);
  border-radius: 999px; padding: 6px 13px; cursor: pointer;
  font-size: 13px; font-weight: 600; color: var(--muted);
  white-space: nowrap; transition: background .12s, color .12s, border-color .12s;
}
.chip .n { font-size: 11px; opacity: .75; margin-left: 4px;
           font-variant-numeric: tabular-nums; }
.chip.active {
  background: var(--card2); border-color: var(--accent); color: var(--text);
}

/* ── корзина ───────────────────────────────────────────────────────── */
main { padding: 0 14px; }
.cat {
  margin-top: 16px; background: var(--card);
  border: 1px solid var(--line); border-radius: 14px; overflow: hidden;
  scroll-margin-top: 178px;
}
.cat-h {
  display: flex; align-items: baseline; gap: 8px;
  padding: 9px 14px; background: var(--card2);
  border-bottom: 1px solid var(--line);
  font-size: 11px; font-weight: 700; letter-spacing: .09em;
  text-transform: uppercase; color: var(--muted);
}
.cat-h .n { font-variant-numeric: tabular-nums; opacity: .75; }
.sec-hint { padding: 8px 14px; font-size: 12px; color: var(--muted);
            border-bottom: 1px dashed var(--line); }

.row-item {
  display: grid; grid-template-columns: 1fr auto; gap: 6px 10px;
  align-items: center; padding: 11px 12px 11px 14px;
  border-bottom: 1px solid var(--line);
  border-left: 3px solid transparent;
  transition: border-color .12s, background .12s;
}
.row-item:last-child { border-bottom: 0; }
.row-item.edited {
  border-left-color: var(--accent);
  background: color-mix(in srgb, var(--accent) 7%, var(--card));
}
.name { font-weight: 600; font-size: 15px; min-width: 0; }
.tag {
  display: inline-block; margin-left: 7px; padding: 1px 7px;
  border-radius: 999px; font-size: 10.5px; font-weight: 700;
  letter-spacing: .03em; vertical-align: 2px;
}
.tag.minus { color: var(--danger); border: 1px solid var(--danger); }
.tag.warn { color: var(--warn); border: 1px solid var(--warn); }
.sub {
  grid-column: 1; font-size: 12px; color: var(--muted); margin-top: 2px;
  font-variant-numeric: tabular-nums;
}
.ctl { grid-row: 1 / span 2; grid-column: 2; display: flex; align-items: center; gap: 6px; }
.qbtn {
  width: 42px; height: 42px; border-radius: 12px;
  border: 1px solid var(--line); background: var(--card2);
  font-size: 22px; line-height: 1; cursor: pointer;
  transition: background .12s, transform .06s;
}
.qbtn:active { transform: scale(.94); background: var(--line); }
.qty {
  width: 58px; height: 42px; text-align: center;
  background: var(--bg); color: var(--text);
  border: 1px solid var(--line); border-radius: 10px;
  font-size: 16px; font-weight: 700; font-variant-numeric: tabular-nums;
}
.row-item.edited .qty { border-color: var(--accent); color: var(--accent); }
.unit { font-size: 12px; color: var(--muted); min-width: 26px; text-align: center; }

.missing-box { margin: 18px 0 8px; }
.missing-row {
  margin-top: 10px; padding: 10px 14px;
  border: 1px dashed var(--line); border-radius: 12px;
  color: var(--muted); font-size: 13px;
}

/* ── низ ───────────────────────────────────────────────────────────── */
footer#bottom {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 30;
  display: flex; align-items: center; gap: 12px;
  padding: 10px 14px calc(10px + env(safe-area-inset-bottom));
  background: var(--bg); border-top: 1px solid var(--line);
}
.who {
  flex: 0 0 auto; max-width: 34%; overflow: hidden; text-overflow: ellipsis;
  white-space: nowrap; border: 1px solid var(--line); background: var(--card);
  border-radius: 999px; padding: 8px 13px; cursor: pointer;
  font-size: 13px; font-weight: 600; color: var(--text);
}
.who.unset { border-color: var(--accent); color: var(--accent); }
.who-list { display: flex; flex-direction: column; gap: 8px; margin: 12px 0; }
.who-list button {
  text-align: left; padding: 12px 14px; border-radius: 12px;
  border: 1px solid var(--line); background: var(--card2);
  cursor: pointer; font-size: 15px; font-weight: 600;
}
.who-list button:active { background: var(--line); }
#who-input {
  width: 100%; padding: 11px 12px; font-size: 15px;
  background: var(--bg); color: var(--text);
  border: 1px solid var(--line); border-radius: 12px;
}
button.primary.wide { width: 100%; margin-top: 12px; }
.summary { flex: 1; font-size: 12.5px; color: var(--muted);
           font-variant-numeric: tabular-nums; }
.summary b { color: var(--text); }
.summary .ed { color: var(--accent); font-weight: 700; }
button.primary {
  border: 0; border-radius: 12px; padding: 13px 22px;
  background: var(--accent); color: var(--accent-ink);
  font-size: 15px; font-weight: 700; cursor: pointer;
  transition: filter .12s, transform .06s;
}
button.primary:active { transform: scale(.98); filter: brightness(1.06); }
button.primary:disabled { opacity: .55; }
button.ghost {
  background: none; border: 1px solid var(--line); border-radius: 12px;
  padding: 10px 16px; color: var(--muted); cursor: pointer; font-size: 14px;
}
button.ghost.wide { width: 100%; margin-top: 12px; }

/* ── баннеры и прочее ──────────────────────────────────────────────── */
.banner { margin-top: 10px; padding: 9px 12px; border-radius: 10px; font-size: 13px; }
.banner.warn { border: 1px solid var(--warn); color: var(--warn); }
.banner.error { border: 1px solid var(--danger); color: var(--danger); }
.note { margin-top: 8px; font-size: 13px; color: var(--muted); }
.hint { color: var(--muted); font-size: 13px; }
.hidden { display: none !important; }

/* ── шторка результата ─────────────────────────────────────────────── */
.sheet {
  position: fixed; inset: 0; z-index: 50;
  background: rgba(0, 0, 0, .55);
  display: flex; align-items: flex-end; justify-content: center;
}
.sheet-card {
  width: 100%; max-width: 560px; max-height: 86vh; overflow-y: auto;
  background: var(--card); border-radius: 18px 18px 0 0;
  padding: 10px 18px calc(16px + env(safe-area-inset-bottom));
  box-shadow: var(--shadow);
}
.sheet-grip {
  width: 40px; height: 4px; border-radius: 2px;
  background: var(--line); margin: 4px auto 12px;
}
.sheet h2 { margin: 0 0 6px; font-size: 17px; }
.result-meta { font-size: 12.5px; color: var(--muted);
               font-variant-numeric: tabular-nums; }
.sheet pre {
  margin-top: 12px; padding: 12px; overflow-x: auto;
  background: var(--bg); border: 1px solid var(--line); border-radius: 10px;
  font-size: 12.5px; white-space: pre-wrap; word-break: break-word;
}

@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; }
}
@media (min-width: 700px) {
  header#top, main { max-width: 680px; margin-left: auto; margin-right: auto; }
  header#top { border-left: 1px solid var(--line); border-right: 1px solid var(--line); }
  footer#bottom { padding-left: calc(50vw - 326px); padding-right: calc(50vw - 326px); }
}
