:root {
  --paper: #F5F6F2;
  --surface: #FFFFFF;
  --ink: #1C2220;
  --ink-2: #59625E;
  --line: #DADDD6;
  --kraft: #C49A5E;
  --kraft-bg: #F1E6D4;
  --kraft-ink: #6E4E22;
  --label: #FFD23F;
  --label-ink: #1C2220;
  --danger: #C8372D;
  --warn: #B86E00;
  --ok: #2F7A4B;
  --radius-s: 6px;
  --radius-m: 12px;
  --tabbar-h: 58px;
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-t: env(safe-area-inset-top, 0px);
  --mono: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --paper: #131614;
    --surface: #1D211F;
    --ink: #E9ECE6;
    --ink-2: #9AA39E;
    --line: #2F3532;
    --kraft: #C49A5E;
    --kraft-bg: #2C251B;
    --kraft-ink: #E2C08C;
    --danger: #FF6B5E;
    --warn: #F0A63C;
    --ok: #5CC489;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  font: 16px/1.45 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  background: var(--paper);
  color: var(--ink);
  -webkit-text-size-adjust: 100%;
  -webkit-tap-highlight-color: transparent;
}
a { color: inherit; }
button, input, select, textarea { font: inherit; color: inherit; }
:focus-visible { outline: 2px solid var(--label); outline-offset: 2px; }

#view {
  padding: calc(var(--safe-t) + 14px) 16px calc(var(--tabbar-h) + var(--safe-b) + 24px);
  max-width: 680px;
  margin: 0 auto;
}
body.no-tabs #view { padding-bottom: 32px; }

h1 { font-size: 26px; line-height: 1.2; margin: 6px 0 4px; letter-spacing: -0.01em; }
h2 { font-size: 17px; margin: 28px 0 10px; }
.muted { color: var(--ink-2); }
.small { font-size: 14px; }
.mono { font-family: var(--mono); }

/* ── Нижняя панель ── */
#tabs {
  position: fixed; inset: auto 0 0 0;
  height: calc(var(--tabbar-h) + var(--safe-b));
  padding-bottom: var(--safe-b);
  display: flex;
  background: color-mix(in srgb, var(--surface) 92%, transparent);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border-top: 1px solid var(--line);
  z-index: 20;
}
body.no-tabs #tabs { display: none; }
#tabs a {
  flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 2px; text-decoration: none; font-size: 11px; color: var(--ink-2);
}
#tabs a svg { width: 24px; height: 24px; }
#tabs a.active { color: var(--ink); font-weight: 600; }
#tabs a.active svg { color: var(--ink); }

/* ── Кнопки ── */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  min-height: 44px; padding: 0 16px;
  border-radius: var(--radius-s);
  border: 1px solid var(--line);
  background: var(--surface);
  text-decoration: none; cursor: pointer; font-weight: 500;
}
.btn:active { transform: translateY(1px); }
.btn.primary { background: var(--label); color: var(--label-ink); border-color: transparent; font-weight: 600; }
.btn.danger { color: var(--danger); }
.btn.block { width: 100%; }
.btn.small { min-height: 34px; padding: 0 12px; font-size: 14px; }
.btn[disabled] { opacity: .5; }
.row { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.row > .grow { flex: 1; }
.actions { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin-top: 16px; }

/* ── Формы ── */
label.field { display: block; margin: 12px 0; }
label.field > span { display: block; font-size: 14px; color: var(--ink-2); margin-bottom: 4px; }
input[type=text], input[type=search], input[type=password], input[type=number],
input[type=date], select, textarea {
  width: 100%; min-height: 44px; padding: 10px 12px;
  border: 1px solid var(--line); border-radius: var(--radius-s);
  background: var(--surface);
  font-size: 16px; /* меньше 16px — iOS зумит страницу при фокусе */
}
textarea { min-height: 80px; resize: vertical; }
.two { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.seg { display: flex; border: 1px solid var(--line); border-radius: var(--radius-s); overflow: hidden; background: var(--surface); }
.seg button { flex: 1; min-height: 40px; border: 0; background: none; cursor: pointer; }
.seg button.on { background: var(--ink); color: var(--paper); font-weight: 600; }

/* ── Карточки узлов: тара — крафт, предмет — белая бумага ── */
.list { display: flex; flex-direction: column; gap: 6px; padding: 0; margin: 0; list-style: none; }
.node {
  display: flex; align-items: center; gap: 12px;
  padding: 10px 12px; min-height: 56px;
  border-radius: var(--radius-s);
  border: 1px solid var(--line);
  background: var(--surface);
  text-decoration: none;
}
.node.container { background: var(--kraft-bg); border-color: color-mix(in srgb, var(--kraft) 45%, transparent); }
.node .thumb {
  width: 40px; height: 40px; flex: none; border-radius: 4px; object-fit: cover;
  display: grid; place-items: center; color: var(--ink-2);
}
.node.container .thumb { color: var(--kraft-ink); }
.node .thumb svg { width: 24px; height: 24px; }
.node .body { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.node .title { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.node .sub { font-size: 13px; color: var(--ink-2); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.node .count { font-size: 14px; color: var(--kraft-ink); font-variant-numeric: tabular-nums; }
.node.dim { opacity: .55; }

.badge {
  display: inline-block; font-size: 12px; padding: 1px 7px; border-radius: 999px;
  border: 1px solid currentColor; vertical-align: middle; white-space: nowrap;
}
.badge.danger { color: var(--danger); }
.badge.warn { color: var(--warn); }
.badge.kraft { color: var(--kraft-ink); }

/* ── Путь до вещи — вложенные бирки ── */
.path { display: flex; flex-wrap: wrap; align-items: center; gap: 4px; margin: 4px 0 8px; }
.path a {
  font-size: 13px; padding: 3px 8px 3px 6px;
  background: var(--kraft-bg); color: var(--kraft-ink);
  border: 1px solid color-mix(in srgb, var(--kraft) 45%, transparent);
  border-radius: 3px 10px 10px 3px;
  text-decoration: none; position: relative;
}
.path a::before {
  content: ""; display: inline-block; width: 5px; height: 5px; border-radius: 50%;
  background: var(--paper); border: 1px solid var(--kraft); margin-right: 5px; vertical-align: 1px;
}
.path .sep { color: var(--ink-2); font-size: 12px; }

/* ── Страница узла ── */
.kind-line { font-size: 14px; color: var(--ink-2); display: flex; gap: 8px; align-items: center; }
.code-chip {
  font-family: var(--mono); font-weight: 600; font-size: 14px; letter-spacing: .05em;
  padding: 2px 8px; border-radius: 3px; background: var(--label); color: var(--label-ink);
}
.photos { display: flex; gap: 8px; overflow-x: auto; margin: 14px -16px 0; padding: 0 16px 4px; scroll-snap-type: x mandatory; }
.photos img, .photos .add-photo {
  width: 120px; height: 120px; flex: none; object-fit: cover; border-radius: var(--radius-s);
  scroll-snap-align: start; cursor: pointer;
}
.photos .add-photo {
  display: grid; place-items: center; border: 1.5px dashed var(--line); color: var(--ink-2);
  font-size: 14px; text-align: center; background: none;
}
dl.facts { display: grid; grid-template-columns: auto 1fr; gap: 6px 16px; margin: 16px 0 0; }
dl.facts dt { color: var(--ink-2); font-size: 14px; padding-top: 1px; }
dl.facts dd { margin: 0; }
.desc { white-space: pre-wrap; margin: 12px 0 0; }
.tags { display: flex; flex-wrap: wrap; gap: 6px; }
.tag {
  font-size: 13px; padding: 3px 10px; border-radius: 999px;
  border: 1px solid var(--line); background: var(--surface); text-decoration: none; color: var(--ink-2);
}
.tag::before { content: "#"; opacity: .5; }
.history { list-style: none; padding: 0; margin: 0; font-size: 14px; }
.history li { padding: 8px 0; border-bottom: 1px solid var(--line); display: flex; gap: 10px; }
.history time { color: var(--ink-2); flex: none; width: 88px; font-variant-numeric: tabular-nums; }

/* ── Сканер ── */
.scanner {
  position: relative; margin: 0 -16px; aspect-ratio: 1 / 1; max-height: 58vh; width: calc(100% + 32px);
  background: #000; overflow: hidden;
}
@media (min-width: 600px) { .scanner { margin: 0; width: 100%; border-radius: var(--radius-m); } }
.scanner video { width: 100%; height: 100%; object-fit: cover; display: block; }
.scanner .frame { position: absolute; inset: 18%; pointer-events: none; }
.scanner .frame i { position: absolute; width: 34px; height: 34px; border: 4px solid var(--label); }
.scanner .frame i:nth-child(1) { top: 0; left: 0; border-right: 0; border-bottom: 0; }
.scanner .frame i:nth-child(2) { top: 0; right: 0; border-left: 0; border-bottom: 0; }
.scanner .frame i:nth-child(3) { bottom: 0; left: 0; border-right: 0; border-top: 0; }
.scanner .frame i:nth-child(4) { bottom: 0; right: 0; border-left: 0; border-top: 0; }
.scanner.hit .frame i { border-color: #fff; }
.scanner .msg {
  position: absolute; inset: 0; display: grid; place-items: center; padding: 24px; text-align: center;
  color: #fff; background: rgba(0, 0, 0, .6);
}
.scanner .msg[hidden] { display: none; }
.scanner .zoom {
  position: absolute; right: 12px; bottom: 12px; min-width: 48px; height: 40px;
  border-radius: 20px; border: 0; background: rgba(0, 0, 0, .55); color: #fff;
  font-weight: 600; cursor: pointer;
}
.scanner .zoom.on { background: var(--label); color: var(--label-ink); }
.target {
  margin: 12px 0; padding: 12px; border-radius: var(--radius-s);
  border: 2px solid var(--label); background: var(--surface);
  display: flex; align-items: center; gap: 10px;
}
.target .grow { min-width: 0; }
.target .title { font-weight: 600; }
.putlog li { animation: drop .25s ease-out; }
@keyframes drop { from { transform: translateY(-6px); opacity: 0; } }
@media (prefers-reduced-motion: reduce) { .putlog li { animation: none; } }

/* ── Модальное окно (лист снизу) ── */
.sheet-back {
  position: fixed; inset: 0; background: rgba(0, 0, 0, .4); z-index: 50;
  display: flex; align-items: flex-end; justify-content: center;
}
.sheet {
  width: 100%; max-width: 680px; max-height: 92vh; overflow-y: auto;
  background: var(--paper); border-radius: 16px 16px 0 0;
  padding: 8px 16px calc(20px + var(--safe-b));
  animation: up .22s ease-out;
}
@keyframes up { from { transform: translateY(40px); opacity: .4; } }
@media (prefers-reduced-motion: reduce) { .sheet { animation: none; } }
.sheet .grip { width: 36px; height: 5px; border-radius: 3px; background: var(--line); margin: 0 auto 10px; }
.sheet h2 { margin-top: 4px; }
.viewer { position: fixed; inset: 0; background: #000; z-index: 60; display: flex; flex-direction: column; }
.viewer img { flex: 1; min-height: 0; object-fit: contain; width: 100%; }
.viewer .row { padding: 12px 16px calc(12px + var(--safe-b)); justify-content: space-between; }

/* ── Тост ── */
#toast {
  position: fixed; left: 50%; bottom: calc(var(--tabbar-h) + var(--safe-b) + 14px);
  transform: translateX(-50%); z-index: 70;
  background: var(--ink); color: var(--paper);
  padding: 10px 16px; border-radius: var(--radius-s); font-size: 15px;
  max-width: calc(100% - 32px); box-shadow: 0 6px 20px rgba(0,0,0,.25);
}
#toast[hidden] { display: none; }
#toast.error { background: var(--danger); color: #fff; }

.empty { padding: 28px 8px; text-align: center; color: var(--ink-2); }
.empty .btn { margin-top: 12px; }
.login { max-width: 360px; margin: 18vh auto 0; }
.login h1 { font-size: 30px; }
