:root {
  --brand: #f5a623;
  --brand-strong: #d9860a;
  --brand-ink: #3a2500;
  --brand-soft: #fff4e0;
  --bg: #f4f5f7;
  --surface: #ffffff;
  --surface-2: #f8f9fb;
  --ink: #1b1f24;
  --ink-2: #5a636e;
  --line: #e2e5ea;
  --ok: #1f8a4c;
  --ok-soft: #e3f5ea;
  --warn: #b25e00;
  --warn-soft: #fff1dc;
  --bad: #c62f2f;
  --bad-soft: #fde8e8;
  --info: #2f6fd6;
  --info-soft: #e6effd;
  --radius: 14px;
  --shadow: 0 1px 2px rgb(16 24 40 / 6%), 0 2px 8px rgb(16 24 40 / 6%);
  --tap: 52px;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root {
    --brand-ink: #1a1000;
    --brand-soft: #3a2a10;
    --bg: #111317;
    --surface: #1a1d22;
    --surface-2: #22262c;
    --ink: #eef0f3;
    --ink-2: #a3abb5;
    --line: #2f343b;
    --ok: #4cc782;
    --ok-soft: #173826;
    --warn: #f0a54a;
    --warn-soft: #3a2a14;
    --bad: #f07272;
    --bad-soft: #3d1c1c;
    --info: #7aa7ff;
    --info-soft: #1a2a45;
    --shadow: 0 1px 2px rgb(0 0 0 / 40%);
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  font: 16px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--ink);
  -webkit-tap-highlight-color: transparent;
  min-height: 100dvh;
}
[hidden] { display: none !important; }
a { color: inherit; }
h1, h2, h3 { line-height: 1.2; margin: 0; }
h1 { font-size: 1.5rem; }
h2 { font-size: 1.15rem; }
img { max-width: 100%; }
.muted { color: var(--ink-2); }
.small { font-size: 0.875rem; }
.mono { font-family: ui-monospace, "Cascadia Mono", Consolas, monospace; font-size: 0.92em; overflow-wrap: anywhere; }

/* ---------- Top bar ---------- */
.topbar {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; gap: 12px;
  padding: 8px max(16px, env(safe-area-inset-left));
  background: var(--surface);
  border-bottom: 1px solid var(--line);
}
.brand { display: flex; align-items: center; gap: 10px; text-decoration: none; font-size: 1.1rem; white-space: nowrap; }
.brand img { border-radius: 8px; }
.tabs { display: flex; gap: 4px; margin-left: auto; }
.tabs a {
  display: flex; align-items: center; gap: 6px;
  min-height: 44px; padding: 0 14px; border-radius: 10px;
  text-decoration: none; color: var(--ink-2); font-weight: 600;
}
.tabs a:hover { background: var(--surface-2); color: var(--ink); }
.tabs a[aria-current="page"] { background: var(--brand-soft); color: var(--ink); box-shadow: inset 0 -3px 0 var(--brand); }
.tabs .ico { font-size: 1.15rem; }
.user-btn {
  min-height: 44px; padding: 0 14px; border-radius: 999px;
  border: 1px solid var(--line); background: var(--surface-2); color: var(--ink);
  font: inherit; font-weight: 600; cursor: pointer; white-space: nowrap;
}

@media (max-width: 760px) {
  .topbar { padding-bottom: 8px; }
  .brand span { display: none; }
  .tabs {
    position: fixed; left: 0; right: 0; bottom: 0; z-index: 20;
    margin: 0; justify-content: space-around; gap: 0;
    padding: 6px 6px max(6px, env(safe-area-inset-bottom));
    background: var(--surface); border-top: 1px solid var(--line);
  }
  .tabs a { flex-direction: column; gap: 0; font-size: 0.75rem; padding: 4px 10px; flex: 1; justify-content: center; }
  .tabs a[aria-current="page"] { box-shadow: inset 0 3px 0 var(--brand); }
  .user-btn { margin-left: auto; }
  main { padding-bottom: 96px !important; }
}

/* ---------- Layout ---------- */
main { max-width: 1180px; margin: 0 auto; padding: 20px 16px 40px; outline: none; }
.page-head { display: flex; flex-wrap: wrap; align-items: center; gap: 12px; margin-bottom: 16px; }
.page-head h1 { margin-right: auto; }
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); padding: 18px; }
.card + .card { margin-top: 16px; }
.card h2 { margin-bottom: 12px; }
.stack > * + * { margin-top: 12px; }
.row { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; }
.grid-2 { display: grid; grid-template-columns: repeat(auto-fit, minmax(280px, 1fr)); gap: 16px; }
.spacer { flex: 1; }

/* ---------- Buttons ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  min-height: 44px; padding: 0 18px; border-radius: 12px;
  border: 1px solid var(--line); background: var(--surface); color: var(--ink);
  font: inherit; font-weight: 600; text-decoration: none; cursor: pointer;
  transition: background 0.12s, transform 0.06s;
}
.btn:hover { background: var(--surface-2); }
.btn:active { transform: scale(0.98); }
.btn:disabled { opacity: 0.55; cursor: not-allowed; }
.btn-primary { background: var(--brand); border-color: var(--brand); color: var(--brand-ink); }
.btn-primary:hover { background: var(--brand-strong); border-color: var(--brand-strong); }
.btn-danger { color: var(--bad); border-color: color-mix(in srgb, var(--bad) 40%, var(--line)); }
.btn-danger:hover { background: var(--bad-soft); }
.btn-ghost { border-color: transparent; background: transparent; }
.btn-lg { min-height: var(--tap); font-size: 1.05rem; padding: 0 22px; }
.btn-block { width: 100%; }
.btn-sm { min-height: 36px; padding: 0 12px; font-size: 0.9rem; border-radius: 10px; }

/* ---------- Forms ---------- */
label { display: block; font-weight: 600; font-size: 0.9rem; margin-bottom: 6px; }
.field + .field { margin-top: 14px; }
.hint { font-size: 0.82rem; color: var(--ink-2); margin-top: 4px; }
input, select, textarea {
  width: 100%; min-height: 48px; padding: 10px 14px;
  border: 1px solid var(--line); border-radius: 12px;
  background: var(--surface); color: var(--ink); font: inherit;
}
textarea { min-height: 88px; resize: vertical; }
input:focus-visible, select:focus-visible, textarea:focus-visible, .btn:focus-visible, .tabs a:focus-visible {
  outline: 3px solid color-mix(in srgb, var(--brand) 60%, transparent); outline-offset: 1px;
}
.input-row { display: flex; gap: 8px; }
.input-row > input, .input-row > select { flex: 1; min-width: 0; }
.loc-fields { display: grid; grid-template-columns: repeat(4, 1fr); gap: 10px; }
@media (max-width: 520px) { .loc-fields { grid-template-columns: repeat(2, 1fr); } }
.loc-fields label { font-weight: 500; color: var(--ink-2); }
.checkbox { display: flex; align-items: center; gap: 8px; font-weight: 500; margin: 0; cursor: pointer; min-height: 44px; }
.checkbox input { width: 22px; min-height: 22px; height: 22px; accent-color: var(--brand); }

/* ---------- Badges & chips ---------- */
.badge { display: inline-flex; align-items: center; gap: 4px; padding: 2px 10px; border-radius: 999px; font-size: 0.8rem; font-weight: 600; background: var(--surface-2); color: var(--ink-2); border: 1px solid var(--line); white-space: nowrap; }
.badge-ok { background: var(--ok-soft); color: var(--ok); border-color: transparent; }
.badge-warn { background: var(--warn-soft); color: var(--warn); border-color: transparent; }
.badge-bad { background: var(--bad-soft); color: var(--bad); border-color: transparent; }
.badge-info { background: var(--info-soft); color: var(--info); border-color: transparent; }
.loc { display: inline-flex; gap: 4px; align-items: center; font-weight: 600; }

/* ---------- Login ---------- */
.login { max-width: 460px; margin: 6vh auto 0; }
.login .logo { display: flex; align-items: center; gap: 12px; margin-bottom: 20px; }
.user-pick { display: grid; grid-template-columns: repeat(auto-fill, minmax(130px, 1fr)); gap: 10px; }
.user-pick button {
  min-height: 64px; border-radius: 12px; border: 1px solid var(--line);
  background: var(--surface-2); color: var(--ink); font: inherit; font-weight: 600; cursor: pointer;
}
.user-pick button[aria-pressed="true"] { border-color: var(--brand); background: var(--brand-soft); box-shadow: inset 0 0 0 2px var(--brand); }
.pin-display { display: flex; justify-content: center; gap: 12px; margin: 18px 0; min-height: 22px; }
.pin-display span { width: 16px; height: 16px; border-radius: 50%; background: var(--line); }
.pin-display span.on { background: var(--brand); }
.keypad { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; }
.keypad button {
  min-height: 64px; font: inherit; font-size: 1.5rem; font-weight: 600;
  border-radius: 14px; border: 1px solid var(--line); background: var(--surface); color: var(--ink); cursor: pointer;
}
.keypad button:active { background: var(--brand-soft); }

/* ---------- Scan ---------- */
.scan-layout { display: grid; grid-template-columns: minmax(0, 1.25fr) minmax(0, 1fr); gap: 16px; align-items: start; }
@media (max-width: 900px) { .scan-layout { grid-template-columns: 1fr; } }
.scan-input { display: flex; gap: 8px; }
.scan-input input { font-size: 1.2rem; min-height: 60px; }
.scan-input .btn { min-height: 60px; }
.camera-box {
  position: relative; margin-top: 14px; border-radius: var(--radius); overflow: hidden;
  background: #0d0f12; aspect-ratio: 4 / 3; display: grid; place-items: center; color: #cfd5dc;
}
.camera-box #reader { position: absolute; inset: 0; width: 100%; }
.camera-box #reader video { width: 100% !important; height: 100% !important; object-fit: cover; }
.camera-placeholder { text-align: center; padding: 20px; z-index: 1; }
.camera-placeholder .big { font-size: 3rem; line-height: 1; margin-bottom: 8px; }
.camera-controls { display: flex; gap: 8px; margin-top: 10px; flex-wrap: wrap; }
.camera-controls select { flex: 1; min-width: 160px; }

/* ---------- Lists ---------- */
.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 12px; margin-bottom: 16px; }
.stat { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px 16px; box-shadow: var(--shadow); text-decoration: none; display: block; }
.stat .num { font-size: 1.75rem; font-weight: 700; font-variant-numeric: tabular-nums; }
.stat .lbl { color: var(--ink-2); font-size: 0.85rem; font-weight: 600; }
.stat.alert .num { color: var(--warn); }
.filters { display: grid; grid-template-columns: minmax(200px, 2fr) repeat(2, minmax(140px, 1fr)) auto; gap: 10px; align-items: center; margin-bottom: 14px; }
@media (max-width: 760px) { .filters { grid-template-columns: 1fr 1fr; } .filters .search { grid-column: 1 / -1; } }

.item-list { display: grid; gap: 10px; }
.item-row {
  display: grid; grid-template-columns: 64px minmax(0, 1fr) auto; gap: 14px; align-items: center;
  padding: 10px 14px 10px 10px; border-radius: var(--radius); border: 1px solid var(--line);
  background: var(--surface); text-decoration: none; box-shadow: var(--shadow);
}
.item-row:hover { border-color: color-mix(in srgb, var(--brand) 50%, var(--line)); }
.thumb { width: 64px; height: 64px; border-radius: 10px; background: var(--surface-2); display: grid; place-items: center; overflow: hidden; color: var(--ink-2); font-size: 1.6rem; }
.thumb img { width: 100%; height: 100%; object-fit: cover; }
.item-row .title { font-weight: 650; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.item-row .meta { display: flex; flex-wrap: wrap; gap: 6px 12px; font-size: 0.85rem; color: var(--ink-2); margin-top: 2px; }
.stock-pill { text-align: right; font-variant-numeric: tabular-nums; }
.stock-pill .n { font-size: 1.4rem; font-weight: 700; }
.stock-pill .u { display: block; font-size: 0.75rem; color: var(--ink-2); }
.stock-pill.low .n { color: var(--warn); }
.stock-pill.out .n { color: var(--bad); }
.empty { text-align: center; padding: 40px 16px; color: var(--ink-2); }
.more { display: flex; justify-content: center; margin-top: 14px; }

/* ---------- Item detail ---------- */
.item-hero { display: grid; grid-template-columns: 220px minmax(0, 1fr); gap: 20px; }
@media (max-width: 640px) { .item-hero { grid-template-columns: 1fr; } }
.item-photo { aspect-ratio: 1; border-radius: var(--radius); overflow: hidden; background: var(--surface-2); display: grid; place-items: center; font-size: 4rem; color: var(--ink-2); }
.item-photo img { width: 100%; height: 100%; object-fit: cover; }
@media (max-width: 640px) { .item-photo { max-height: 240px; aspect-ratio: auto; height: 240px; } }
.facts { display: grid; grid-template-columns: max-content minmax(0, 1fr); gap: 6px 16px; margin: 12px 0 0; }
.facts dt { color: var(--ink-2); font-weight: 600; font-size: 0.9rem; }
.facts dd { margin: 0; }
.big-stock { display: flex; align-items: baseline; gap: 10px; margin-top: 14px; }
.big-stock .n { font-size: 3rem; font-weight: 750; line-height: 1; font-variant-numeric: tabular-nums; }

.move { margin-top: 16px; }
.stepper { display: grid; grid-template-columns: 72px minmax(0, 1fr) 72px; gap: 10px; }
.stepper button { min-height: 72px; font-size: 2rem; font-weight: 600; border-radius: 14px; border: 1px solid var(--line); background: var(--surface-2); color: var(--ink); cursor: pointer; }
.stepper input { min-height: 72px; text-align: center; font-size: 2rem; font-weight: 700; font-variant-numeric: tabular-nums; }
.move-actions { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-top: 12px; }
.move-actions .btn { min-height: 72px; font-size: 1.15rem; border-radius: 14px; }
.btn-out { background: var(--bad-soft); color: var(--bad); border-color: transparent; }
.btn-out:hover { background: color-mix(in srgb, var(--bad-soft) 80%, var(--bad)); }
.btn-in { background: var(--ok-soft); color: var(--ok); border-color: transparent; }
.btn-in:hover { background: color-mix(in srgb, var(--ok-soft) 80%, var(--ok)); }

/* ---------- Tables ---------- */
.table-wrap { overflow-x: auto; border: 1px solid var(--line); border-radius: var(--radius); background: var(--surface); }
table { width: 100%; border-collapse: collapse; font-size: 0.93rem; }
th, td { text-align: left; padding: 10px 14px; border-bottom: 1px solid var(--line); vertical-align: middle; }
th { font-size: 0.8rem; text-transform: uppercase; letter-spacing: 0.04em; color: var(--ink-2); background: var(--surface-2); }
tr:last-child td { border-bottom: 0; }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }
.delta-pos { color: var(--ok); font-weight: 700; }
.delta-neg { color: var(--bad); font-weight: 700; }
td a { text-decoration: none; font-weight: 600; }
td a:hover { text-decoration: underline; }

/* ---------- Photo picker ---------- */
.photo-picker { display: flex; gap: 14px; align-items: center; flex-wrap: wrap; }
.photo-picker .thumb { width: 96px; height: 96px; }

/* ---------- Dialog ---------- */
dialog {
  border: 0; border-radius: 18px; padding: 0; width: min(440px, calc(100vw - 32px));
  background: var(--surface); color: var(--ink); box-shadow: 0 20px 60px rgb(0 0 0 / 30%);
}
dialog::backdrop { background: rgb(10 12 16 / 55%); }
dialog form { padding: 20px; }
dialog h2 { margin-bottom: 14px; }
dialog .actions { display: flex; justify-content: flex-end; gap: 10px; margin-top: 18px; }

/* ---------- Toasts ---------- */
.toasts { position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%); z-index: 100; display: grid; gap: 8px; width: min(520px, calc(100vw - 32px)); pointer-events: none; }
@media (max-width: 760px) { .toasts { bottom: 92px; } }
.toast { padding: 14px 18px; border-radius: 14px; background: var(--ink); color: var(--surface); font-weight: 600; box-shadow: 0 8px 24px rgb(0 0 0 / 25%); animation: toast-in 0.18s ease-out; }
.toast.ok { background: var(--ok); color: #fff; }
.toast.bad { background: var(--bad); color: #fff; }
@keyframes toast-in { from { opacity: 0; transform: translateY(8px); } }

.flash-ok { animation: flash 0.6s ease-out; }
@keyframes flash { from { box-shadow: 0 0 0 4px var(--ok); } }

.spinner { width: 28px; height: 28px; border: 3px solid var(--line); border-top-color: var(--brand); border-radius: 50%; animation: spin 0.8s linear infinite; margin: 40px auto; }
@keyframes spin { to { transform: rotate(360deg); } }

@media (prefers-reduced-motion: reduce) { *, *::before, *::after { animation: none !important; transition: none !important; } }

.keypad button.btn-primary { background: var(--brand); border-color: var(--brand); color: var(--brand-ink); font-size: 1.2rem; }
