:root {
  --navy: #0b2a4a;
  --navy-2: #163d66;
  --lime: #8cc63f;
  --lime-dark: #5f8f1f;
  --bg: #f3f5f8;
  --card: #ffffff;
  --ink: #16202b;
  --muted: #5d6b7a;
  --line: #dde3ea;
  --warn: #b45309;
  --warn-bg: #fff4e0;
  --bad: #b91c1c;
  --radius: 12px;
  --tabs-h: 64px;
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { margin: 0; }
body {
  font: 16px/1.4 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  background: var(--bg); color: var(--ink);
  padding-bottom: calc(var(--tabs-h) + env(safe-area-inset-bottom) + 16px);
  -webkit-tap-highlight-color: transparent;
}
a { color: var(--navy-2); }
.topbar {
  position: sticky; top: 0; z-index: 10;
  display: flex; align-items: center; justify-content: space-between; gap: 8px;
  background: var(--navy); color: #fff;
  padding: calc(env(safe-area-inset-top) + 10px) 16px 10px;
}
.brand { display: flex; align-items: center; gap: 10px; font-weight: 600; }
.logo { background: var(--lime); color: var(--navy); font-weight: 800; border-radius: 6px; padding: 2px 7px; }
.pill { font-size: 12px; background: var(--lime); color: var(--navy); border-radius: 999px; padding: 4px 10px; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 55%; }
main { max-width: 820px; margin: 0 auto; padding: 16px; }
h1 { font-size: 22px; margin: 4px 0 12px; }
h2 { font-size: 17px; margin: 20px 0 8px; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px; margin-bottom: 12px; }
.row { display: flex; gap: 10px; align-items: center; }
.row.wrap { flex-wrap: wrap; }
.grow { flex: 1; min-width: 0; }
.stack > * + * { margin-top: 10px; }

.tabs {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 10;
  display: flex; background: #fff; border-top: 1px solid var(--line);
  padding-bottom: env(safe-area-inset-bottom); height: calc(var(--tabs-h) + env(safe-area-inset-bottom));
}
.tabs a { flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px; font-size: 12px; color: var(--muted); text-decoration: none; }
.tabs svg { width: 24px; height: 24px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.tabs a.on { color: var(--navy); font-weight: 600; }
.tabs a.on svg { stroke: var(--navy); }

button, .btn {
  font: inherit; font-weight: 600; border: 0; border-radius: 10px; padding: 12px 16px; min-height: 46px;
  background: var(--navy); color: #fff; cursor: pointer; text-decoration: none; display: inline-flex; align-items: center; justify-content: center; gap: 6px;
}
button:disabled { opacity: .5; }
.btn-lime { background: var(--lime); color: var(--navy); }
.btn-ghost { background: #fff; color: var(--navy); border: 1px solid var(--line); }
.btn-danger { background: #fff; color: var(--bad); border: 1px solid #f1c4c4; }
.btn-block { width: 100%; }
.btn-big { min-height: 58px; font-size: 18px; }
.btn-sm { min-height: 36px; padding: 6px 12px; font-size: 14px; }

label.f { display: block; font-size: 13px; font-weight: 600; color: var(--muted); margin: 12px 0 4px; }
input, select, textarea {
  font: inherit; width: 100%; padding: 11px 12px; border: 1px solid var(--line); border-radius: 10px; background: #fff; color: var(--ink); min-height: 46px;
}
textarea { min-height: 70px; }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--lime); border-color: var(--lime); }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 0 12px; }
@media (max-width: 480px) { .grid2 { grid-template-columns: 1fr; } }

.seg { display: flex; border: 1px solid var(--line); border-radius: 10px; overflow: hidden; }
.seg button { flex: 1; background: #fff; color: var(--ink); border-radius: 0; font-weight: 500; }
.seg button.on { background: var(--navy); color: #fff; }

.qty { display: flex; align-items: stretch; gap: 8px; }
.qty button { width: 64px; font-size: 26px; background: #fff; color: var(--navy); border: 1px solid var(--line); }
.qty input { text-align: center; font-size: 30px; font-weight: 700; min-height: 64px; }

.scanbox { position: relative; background: #000; border-radius: var(--radius); overflow: hidden; aspect-ratio: 4 / 3; max-height: 55vh; width: 100%; }
.scanbox video { width: 100%; height: 100%; object-fit: cover; display: block; }
.scanbox .frame { position: absolute; inset: 18% 22%; border: 3px solid var(--lime); border-radius: 14px; box-shadow: 0 0 0 999px rgba(0,0,0,.35); }
.scanbox .msg { position: absolute; left: 0; right: 0; bottom: 10px; text-align: center; color: #fff; font-size: 14px; text-shadow: 0 1px 2px #000; }
.scanbox.idle { display: flex; align-items: center; justify-content: center; }

.list { background: #fff; border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; }
.li { display: flex; gap: 12px; align-items: center; padding: 10px 12px; border-bottom: 1px solid var(--line); color: inherit; text-decoration: none; }
.li:last-child { border-bottom: 0; }
.thumb { width: 52px; height: 52px; border-radius: 8px; object-fit: cover; background: #e9edf2; flex: none; display: flex; align-items: center; justify-content: center; color: #9aa7b5; font-size: 11px; }
.li .t { font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.li .s { font-size: 13px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.li .q { font-weight: 700; text-align: right; white-space: nowrap; }
.badge { display: inline-block; font-size: 11px; font-weight: 700; border-radius: 999px; padding: 2px 8px; background: #e9edf2; color: var(--muted); margin-left: 4px; vertical-align: middle; }
.badge.warn { background: var(--warn-bg); color: var(--warn); }
.badge.lime { background: #eaf6da; color: var(--lime-dark); }
.badge.bad { background: #fde8e8; color: var(--bad); }

.chips { display: flex; gap: 8px; overflow-x: auto; padding-bottom: 4px; margin: 10px 0; }
.chips button { flex: none; min-height: 36px; padding: 6px 14px; border-radius: 999px; background: #fff; color: var(--ink); border: 1px solid var(--line); font-weight: 500; font-size: 14px; }
.chips button.on { background: var(--navy); color: #fff; border-color: var(--navy); }

.photo { width: 100%; max-height: 300px; object-fit: contain; background: #e9edf2; border-radius: var(--radius); display: block; }
.photo-empty { width: 100%; height: 180px; border: 2px dashed #b8c3cf; border-radius: var(--radius); background: #fff; color: var(--muted); display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 6px; font-weight: 600; cursor: pointer; }
.idtag { font-family: ui-monospace, Menlo, Consolas, monospace; background: #eef2f6; border-radius: 6px; padding: 2px 8px; font-weight: 700; }

.tiles { display: grid; grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); gap: 10px; }
.tile { background: #fff; border: 1px solid var(--line); border-radius: var(--radius); padding: 12px; }
.tile b { display: block; font-size: 26px; }
.tile span { font-size: 13px; color: var(--muted); }

.toast { position: fixed; left: 50%; transform: translateX(-50%); bottom: calc(var(--tabs-h) + env(safe-area-inset-bottom) + 14px); background: var(--navy); color: #fff; padding: 12px 18px; border-radius: 10px; z-index: 30; max-width: calc(100% - 32px); box-shadow: 0 6px 20px rgba(0,0,0,.25); font-weight: 600; }
.toast.err { background: var(--bad); }
.center { text-align: center; }
.menu a { display: flex; justify-content: space-between; align-items: center; padding: 16px 14px; border-bottom: 1px solid var(--line); text-decoration: none; color: inherit; font-weight: 600; }
.menu a:last-child { border-bottom: 0; }
.menu a small { font-weight: 400; color: var(--muted); display: block; }
details summary { cursor: pointer; font-weight: 600; color: var(--navy-2); padding: 8px 0; }
.login { max-width: 360px; margin: 10vh auto; }
.menu a small { order: 2; flex-basis: 100%; } .menu a span { order: 1; }
.overlay { position: fixed; inset: 0; z-index: 50; background: rgba(8, 20, 35, .92); padding: calc(env(safe-area-inset-top) + 16px) 16px 16px; display: flex; flex-direction: column; justify-content: center; }
.overlay .scanbox { max-height: 70vh; }
