:root {
  --bg: #f3f5f6;
  --surface: #ffffff;
  --surface-2: #eef2f3;
  --line: #dde3e6;
  --text: #13232b;
  --muted: #5b6b73;
  --brand: #0f3d4c;
  --brand-2: #155a6e;
  --accent: #12a183;
  --accent-ink: #ffffff;
  --ok: #157a4f;
  --ok-bg: #e3f4ec;
  --warn: #8a5a00;
  --warn-bg: #fff2d6;
  --bad: #b3261e;
  --bad-bg: #fde7e5;
  --cd: #6b3fa0;
  --cd-bg: #efe7f8;
  --focus: #2f80ed;
  --radius: 12px;
  --shadow: 0 1px 2px rgba(16, 35, 43, .06), 0 4px 16px rgba(16, 35, 43, .06);
  --tabs-h: 64px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0d1518;
    --surface: #152126;
    --surface-2: #1b2a30;
    --line: #2a3b42;
    --text: #e6eef1;
    --muted: #93a6ae;
    --brand: #0b2f3b;
    --brand-2: #4fb3c9;
    --accent: #2fc4a2;
    --accent-ink: #062019;
    --ok: #5fd39c;
    --ok-bg: #12352a;
    --warn: #f3c15b;
    --warn-bg: #3a2c0c;
    --bad: #ff8a80;
    --bad-bg: #3d1614;
    --cd: #c7a6f0;
    --cd-bg: #2d2140;
    --shadow: 0 1px 2px rgba(0, 0, 0, .3);
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--text);
  font: 16px/1.45 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}
a { color: var(--brand-2); }
h1, h2, h3 { line-height: 1.2; margin: 0 0 .5rem; }
h1 { font-size: 1.45rem; letter-spacing: -.01em; }
h2 { font-size: 1.15rem; }
h3 { font-size: 1rem; }
p { margin: 0 0 .75rem; }
:focus-visible { outline: 3px solid var(--focus); outline-offset: 2px; }
.muted { color: var(--muted); }
.hint { color: var(--muted); font-size: .875rem; margin: .35rem 0 0; }
.num { font-variant-numeric: tabular-nums; }
[hidden] { display: none !important; }

/* ------- shell */
.topbar {
  position: sticky; top: 0; z-index: 20; display: flex; align-items: center; justify-content: space-between;
  gap: 12px; padding: calc(10px + env(safe-area-inset-top)) 16px 10px; background: var(--brand); color: #fff;
}
.brand { display: flex; align-items: center; gap: 10px; color: #fff; text-decoration: none; font-weight: 650; font-size: 1.05rem; min-width: 0; }
.brand span { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.user-chip { color: #fff; text-decoration: none; font-size: .875rem; background: rgba(255,255,255,.14); padding: 6px 12px; border-radius: 999px; white-space: nowrap; }
#netbar { position: sticky; top: calc(48px + env(safe-area-inset-top)); z-index: 19; padding: 8px 16px; background: var(--warn-bg); color: var(--warn); font-size: .85rem; font-weight: 600; text-align: center; border-bottom: 1px solid var(--line); }
main { max-width: 980px; margin: 0 auto; padding: 18px 16px calc(var(--tabs-h) + 28px + env(safe-area-inset-bottom)); outline: none; }
.tabs {
  position: fixed; inset: auto 0 0 0; z-index: 20; display: grid; grid-template-columns: repeat(5, 1fr);
  background: var(--surface); border-top: 1px solid var(--line); padding-bottom: env(safe-area-inset-bottom);
}
.tabs a {
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px; height: var(--tabs-h);
  color: var(--muted); text-decoration: none; font-size: .72rem; font-weight: 600;
}
.tabs a svg { width: 24px; height: 24px; }
.tabs a.on { color: var(--brand-2); }
@media (min-width: 900px) {
  .tabs { inset: 0 auto 0 0; width: 92px; grid-template-columns: 1fr; grid-auto-rows: 76px; align-content: start; padding-top: 70px; border-top: 0; border-right: 1px solid var(--line); }
  .tabs a { height: auto; }
  main { padding-bottom: 40px; }
  #app { padding-left: 92px; }
  .topbar { margin-left: -92px; padding-left: 108px; }
}

/* ------- building blocks */
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; box-shadow: var(--shadow); }
.card + .card, .section + .section { margin-top: 14px; }
.section { margin-top: 22px; }
.section-head { display: flex; align-items: baseline; justify-content: space-between; gap: 12px; margin-bottom: 10px; }
.section-head h2 { margin: 0; }
.page-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; margin-bottom: 14px; flex-wrap: wrap; }
.page-head h1 { margin: 0; }
.page-head .sub { color: var(--muted); margin-top: 4px; font-size: .95rem; }
.back { display: inline-flex; align-items: center; gap: 4px; color: var(--muted); text-decoration: none; font-size: .9rem; margin-bottom: 8px; }
.grid { display: grid; gap: 12px; }
.grid.actions { grid-template-columns: repeat(2, 1fr); }
@media (min-width: 640px) { .grid.actions { grid-template-columns: repeat(3, 1fr); } }
.row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.row2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.spacer { flex: 1; }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px; min-height: 44px; padding: 0 16px;
  border-radius: 10px; border: 1px solid var(--line); background: var(--surface); color: var(--text);
  font: inherit; font-weight: 600; text-decoration: none; cursor: pointer; white-space: nowrap;
}
.btn svg { width: 20px; height: 20px; flex: none; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn.danger { background: var(--bad); border-color: var(--bad); color: #fff; }
.btn.ghost { background: transparent; border-color: transparent; }
.btn.small { min-height: 36px; padding: 0 12px; font-size: .875rem; }
.btn.block { width: 100%; }
.btn.icon { padding: 0; width: 44px; }
.btn[disabled] { opacity: .55; cursor: progress; }

.action {
  display: flex; flex-direction: column; align-items: flex-start; gap: 10px; padding: 16px; min-height: 112px;
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow);
  color: var(--text); text-decoration: none; font-weight: 650;
}
.action .ico { width: 42px; height: 42px; border-radius: 11px; display: grid; place-items: center; background: var(--surface-2); color: var(--brand-2); }
.action .ico svg { width: 24px; height: 24px; }
.action small { display: block; font-weight: 400; color: var(--muted); font-size: .8rem; margin-top: 2px; }
.action.receive .ico { background: var(--ok-bg); color: var(--ok); }
.action.dispose .ico { background: var(--bad-bg); color: var(--bad); }
.action.use .ico { background: var(--cd-bg); color: var(--cd); }

.badge { display: inline-flex; align-items: center; gap: 4px; padding: 2px 8px; border-radius: 999px; font-size: .75rem; font-weight: 700; background: var(--surface-2); color: var(--muted); white-space: nowrap; vertical-align: middle; }
.badge.ok { background: var(--ok-bg); color: var(--ok); }
.badge.warn { background: var(--warn-bg); color: var(--warn); }
.badge.bad { background: var(--bad-bg); color: var(--bad); }
.badge.cd { background: var(--cd-bg); color: var(--cd); }

.alerts { display: grid; gap: 10px; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); }
.stat { display: block; padding: 14px; border-radius: var(--radius); background: var(--surface); border: 1px solid var(--line); text-decoration: none; color: var(--text); }
.stat b { display: block; font-size: 1.7rem; line-height: 1.1; font-variant-numeric: tabular-nums; }
.stat span { color: var(--muted); font-size: .85rem; }
.stat.bad { background: var(--bad-bg); border-color: transparent; } .stat.bad b { color: var(--bad); }
.stat.warn { background: var(--warn-bg); border-color: transparent; } .stat.warn b { color: var(--warn); }
.stat.ok b { color: var(--ok); }

/* ------- lists */
.list { display: grid; gap: 8px; }
.list-item {
  display: block; width: 100%; text-align: left; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 12px 14px; color: var(--text); text-decoration: none; font: inherit; cursor: pointer;
}
button.list-item:hover, a.list-item:hover { border-color: var(--brand-2); }
.li-row { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.li-title { font-weight: 650; }
.li-meta { color: var(--muted); font-size: .85rem; margin-top: 2px; }
.li-side { text-align: right; flex: none; }
.big-num { font-size: 1.25rem; font-weight: 700; font-variant-numeric: tabular-nums; }
.big-num small { font-size: .78rem; font-weight: 500; color: var(--muted); }
.empty { text-align: center; color: var(--muted); padding: 28px 12px; border: 1px dashed var(--line); border-radius: var(--radius); }

.pack-card { display: flex; justify-content: space-between; gap: 12px; align-items: center; }
.pc-name { font-weight: 650; }
.pc-meta { color: var(--muted); font-size: .85rem; margin-top: 3px; display: flex; flex-wrap: wrap; gap: 4px 10px; align-items: center; }
.pc-side { text-align: right; flex: none; }
.pc-units { font-weight: 700; font-size: 1.1rem; font-variant-numeric: tabular-nums; }
.pc-units small { font-weight: 500; color: var(--muted); font-size: .78rem; }
.pc-loc { font-size: .8rem; color: var(--muted); }

.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip { padding: 4px 10px; border-radius: 999px; background: var(--surface-2); font-size: .82rem; }
.chip.short { background: var(--warn-bg); color: var(--warn); font-weight: 600; }

/* ------- scanner */
.scan {
  display: flex; align-items: center; gap: 8px; background: var(--surface); border: 2px solid var(--brand-2);
  border-radius: 14px; padding: 6px 6px 6px 14px; box-shadow: var(--shadow);
}
.scan svg.scan-ico { width: 24px; height: 24px; color: var(--brand-2); flex: none; }
.scan input { flex: 1; min-width: 0; border: 0; background: transparent; font: inherit; font-size: 1.05rem; color: var(--text); padding: 10px 0; outline: none; }
.scan .cam { background: var(--brand-2); color: #fff; border-color: transparent; width: auto; padding: 0 14px; }
.scan-help { color: var(--muted); font-size: .85rem; margin: 8px 2px 0; }
.target {
  display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 12px 14px;
  border-radius: var(--radius); background: var(--brand); color: #fff; margin-bottom: 12px;
}
.target small { opacity: .8; display: block; font-size: .78rem; }
.target b { font-size: 1.05rem; }
.target .btn { background: rgba(255,255,255,.15); color: #fff; border-color: transparent; }

.camera-box { position: relative; background: #000; border-radius: 12px; overflow: hidden; aspect-ratio: 3 / 4; max-height: 60vh; margin: 0 auto; }
.camera-box video { width: 100%; height: 100%; object-fit: cover; display: block; }
.camera-box .reticle { position: absolute; inset: 22% 14%; border: 3px solid rgba(255,255,255,.9); border-radius: 16px; box-shadow: 0 0 0 9999px rgba(0,0,0,.35); }
.camera-msg { text-align: center; color: var(--muted); margin-top: 10px; font-size: .9rem; }

/* ------- forms */
form.stack { display: grid; gap: 14px; }
label { display: grid; gap: 6px; font-weight: 600; font-size: .9rem; }
label.check { display: flex; align-items: center; gap: 10px; font-weight: 600; }
label.check input { width: 22px; height: 22px; }
input, select, textarea {
  font: inherit; font-weight: 400; color: var(--text); background: var(--surface); border: 1px solid var(--line);
  border-radius: 10px; padding: 11px 12px; min-height: 46px; width: 100%;
}
textarea { min-height: 80px; resize: vertical; }
input:focus, select:focus, textarea:focus { border-color: var(--brand-2); outline: 2px solid color-mix(in srgb, var(--brand-2) 30%, transparent); }
fieldset { border: 1px solid var(--line); border-radius: var(--radius); padding: 12px 14px 14px; margin: 0; }
fieldset.witness { border-color: var(--cd); background: var(--cd-bg); }
legend { font-weight: 700; padding: 0 6px; }
fieldset.witness legend { color: var(--cd); }
.form-error { color: var(--bad); background: var(--bad-bg); padding: 10px 12px; border-radius: 10px; font-weight: 600; }
.warnbox { color: var(--warn); background: var(--warn-bg); padding: 10px 12px; border-radius: 10px; font-size: .9rem; }
.form-actions { display: flex; gap: 10px; justify-content: flex-end; flex-wrap: wrap; }
.form-actions .btn { flex: 1 1 140px; }

/* ------- sheet (modal) */
.sheet-wrap { position: fixed; inset: 0; z-index: 50; background: rgba(8, 20, 26, .5); display: flex; align-items: flex-end; justify-content: center; animation: fade .15s ease; }
.sheet {
  background: var(--bg); width: 100%; max-width: 620px; max-height: 92vh; overflow: auto; border-radius: 18px 18px 0 0;
  padding-bottom: env(safe-area-inset-bottom); animation: up .2s ease;
}
@media (min-width: 700px) { .sheet-wrap { align-items: center; } .sheet { border-radius: 18px; } }
.sheet-head { position: sticky; top: 0; z-index: 1; display: flex; align-items: center; justify-content: space-between; gap: 8px; padding: 14px 16px; background: var(--bg); border-bottom: 1px solid var(--line); }
.sheet-head h2 { margin: 0; }
.sheet-body { padding: 16px; }
.sheet-body > .card { margin-bottom: 14px; box-shadow: none; }
@keyframes fade { from { opacity: 0; } }
@keyframes up { from { transform: translateY(24px); opacity: .6; } }

/* ------- toasts */
#toasts { position: fixed; z-index: 80; left: 50%; transform: translateX(-50%); bottom: calc(var(--tabs-h) + 14px + env(safe-area-inset-bottom)); display: grid; gap: 8px; width: min(92vw, 460px); pointer-events: none; }
.toast { padding: 12px 16px; border-radius: 12px; background: var(--text); color: var(--bg); font-weight: 600; box-shadow: 0 6px 24px rgba(0,0,0,.25); animation: up .2s ease; }
.toast.ok { background: var(--ok); color: #fff; }
.toast.bad { background: var(--bad); color: #fff; }
.toast.warn { background: #b07400; color: #fff; }

/* ------- 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: .9rem; }
th, td { text-align: left; padding: 9px 10px; border-bottom: 1px solid var(--line); vertical-align: top; }
th { font-size: .78rem; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); background: var(--surface-2); white-space: nowrap; }
td.n, th.n { text-align: right; font-variant-numeric: tabular-nums; }
tr:last-child td { border-bottom: 0; }
tr.is-bad td { background: var(--bad-bg); }
tr.is-warn td { background: var(--warn-bg); }
tr.group td { background: var(--surface-2); font-weight: 700; }

.kv { display: grid; grid-template-columns: max-content 1fr; gap: 6px 16px; font-size: .95rem; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; font-weight: 600; word-break: break-word; }

.timeline { list-style: none; margin: 0; padding: 0; }
.timeline li { padding: 10px 0 10px 18px; border-left: 2px solid var(--line); position: relative; }
.timeline li::before { content: ""; position: absolute; left: -6px; top: 15px; width: 10px; height: 10px; border-radius: 50%; background: var(--brand-2); }
.timeline .when { font-size: .8rem; color: var(--muted); }

/* ------- login */
.login { max-width: 400px; margin: 8vh auto 0; }
.login .logo { display: flex; justify-content: center; margin-bottom: 14px; }
.login h1 { text-align: center; }
.pinpad { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; margin-top: 4px; }
.pinpad button { min-height: 58px; font-size: 1.35rem; font-weight: 600; border-radius: 12px; border: 1px solid var(--line); background: var(--surface); color: var(--text); cursor: pointer; }
.pin-dots { display: flex; justify-content: center; gap: 12px; margin: 6px 0 4px; min-height: 18px; }
.pin-dots i { width: 14px; height: 14px; border-radius: 50%; background: var(--line); }
.pin-dots i.on { background: var(--brand-2); }

/* ------- reports & print */
.report { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 20px; }
.report-head { display: flex; justify-content: space-between; gap: 16px; border-bottom: 2px solid var(--text); padding-bottom: 10px; margin-bottom: 14px; flex-wrap: wrap; }
.report-head h1 { margin: 0 0 2px; }
.report-meta { font-size: .85rem; color: var(--muted); text-align: right; }
.report h2 { margin-top: 18px; }
.report .table-wrap { border-radius: 6px; }
.report table { min-width: 620px; }
@media print { .report table { min-width: 0; } }
.signoff { display: grid; grid-template-columns: 1fr 1fr; gap: 24px; margin-top: 28px; font-size: .9rem; }
.signoff div { border-top: 1px solid var(--text); padding-top: 6px; }
.toolbar { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 14px; }

/* labels: sized by --lw / --lh (mm) */
.labels { --lw: 62mm; --lh: 29mm; --lfs: 8pt; display: flex; flex-wrap: wrap; gap: 4mm; }
.label { width: var(--lw); height: var(--lh); border: 1px dashed #bbb; border-radius: 1.5mm; padding: calc(var(--lh) * .07);
  display: flex; gap: calc(var(--lh) * .08); align-items: center; background: #fff; color: #000; overflow: hidden; }
.label .qr { flex: none; width: calc(var(--lh) * .86); height: calc(var(--lh) * .86); }
.label .qr svg { width: 100%; height: 100%; display: block; }
.label .lt { font-size: var(--lfs); line-height: 1.15; min-width: 0; overflow: hidden; }
.label .lt > * { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.label .lt b { display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; white-space: normal; font-size: 1.1em; line-height: 1.1; }
.label .lt .n { font-weight: 400; }
.label .lt .code { font-family: ui-monospace, Menlo, Consolas, monospace; font-weight: 700; }
.label .lt .cdmark { display: inline-block; border: 1px solid #000; padding: 0 .6mm; font-weight: 700; font-size: .85em; }
.labels.sheet { display: grid; grid-template-columns: repeat(auto-fill, var(--lw)); }

/* steppers for counting */
.stepper { display: inline-flex; align-items: center; border: 1px solid var(--line); border-radius: 10px; overflow: hidden; background: var(--surface); }
.stepper button { width: 34px; min-height: 42px; border: 0; background: var(--surface-2); color: var(--text); font-size: 1.2rem; cursor: pointer; }
.stepper input { width: 42px; min-height: 42px; border: 0; border-radius: 0; text-align: center; padding: 0 4px; -moz-appearance: textfield; }
.stepper input::-webkit-outer-spin-button, .stepper input::-webkit-inner-spin-button { -webkit-appearance: none; margin: 0; }
table.check-table td { vertical-align: middle; }
table.check-table th, table.check-table td { padding: 8px 6px; }
table.check-table td:first-child, table.check-table th:first-child { padding-left: 10px; }
table.compact td, table.compact th { padding: 7px 10px; }
input.filled { border-color: var(--warn); background: var(--warn-bg); }
.card h2 { margin-bottom: 8px; }
.card ul { margin: 0; padding-left: 20px; display: grid; gap: 6px; }

@media print {
  @page { margin: 12mm; }
  body { background: #fff; color: #000; font-size: 11pt; }
  .topbar, .tabs, .toolbar, .no-print, #toasts, .back { display: none !important; }
  #app { padding: 0 !important; }
  main { padding: 0; max-width: none; }
  .report, .card, .table-wrap { border: 0; box-shadow: none; padding: 0; background: #fff; }
  th { background: #eee !important; color: #000; }
  tr.is-bad td { background: #fde7e5 !important; }
  tr.is-warn td { background: #fff2d6 !important; }
  table { font-size: 9pt; }
  tr { page-break-inside: avoid; }
  .report-meta, .muted, .hint { color: #333; }
  .labels.roll { display: block; gap: 0; }
  .labels.roll .label { border: 0; border-radius: 0; break-after: page; page-break-after: always; }
  .labels.sheet { gap: 0; }
  .labels.sheet .label { border: 0; }
  * { -webkit-print-color-adjust: exact; print-color-adjust: exact; }
}
