:root {
  --bg: #f4f2ed;
  --panel: #fff;
  --ink: #1a1a1a;
  --muted: #6a6660;
  --line: #ddd8ce;
  --accent: #1f6b4f;
  --accent-ink: #fff;
  --danger: #a33;
  --warn-bg: #fff6dd;
  --ok: #1f6b4f;
  --err: #a33;
  --font: system-ui, -apple-system, "Segoe UI", sans-serif;
  --touch: 48px;
  --radius: 10px;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  font-family: var(--font);
  color: var(--ink);
  background: var(--bg);
  min-height: 100vh;
  min-height: 100dvh;
}
a { color: var(--accent); }

.top {
  padding: 0.6rem 0.85rem;
  border-bottom: 1px solid var(--line);
  background: var(--panel);
  position: sticky;
  top: 0;
  z-index: 20;
}
.brand {
  font-weight: 700;
  text-decoration: none;
  color: var(--ink);
  font-size: 0.95rem;
}
.wrap { max-width: 960px; margin: 0 auto; padding: 0.85rem; }

.panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 0.85rem;
  margin-bottom: 0.65rem;
}
.row { display: flex; gap: 0.5rem; align-items: center; flex-wrap: wrap; }
.row.between { justify-content: space-between; }
.stack { display: flex; flex-direction: column; gap: 0.55rem; max-width: 420px; }
.stack-full { max-width: none; width: 100%; }
.stack label, .file { display: flex; flex-direction: column; gap: 0.25rem; font-size: 0.9rem; }

input[type="text"],
input[type="number"],
input[type="file"],
input[type="search"] {
  font: inherit;
  font-size: 16px;
  padding: 0.65rem 0.75rem;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  width: 100%;
  min-height: var(--touch);
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.3rem;
  min-height: var(--touch);
  padding: 0.55rem 0.9rem;
  border-radius: 8px;
  border: 1px solid var(--line);
  background: #fff;
  color: var(--ink);
  text-decoration: none;
  cursor: pointer;
  font: inherit;
  font-size: 1rem;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
}
.btn.primary { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }
.btn.danger { background: var(--danger); color: #fff; border-color: var(--danger); }
.btn.small { min-height: 36px; padding: 0.3rem 0.55rem; font-size: 0.9rem; }
.btn-block { width: 100%; }
.btn.disabled, .btn:disabled { opacity: 0.35; pointer-events: none; }

.muted { color: var(--muted); }
.file-line { margin: 0 0 0.75rem; font-size: 0.9rem; word-break: break-all; }

.table { width: 100%; border-collapse: collapse; font-size: 0.9rem; }
.table th, .table td {
  text-align: left;
  padding: 0.45rem 0.3rem;
  border-bottom: 1px solid var(--line);
  vertical-align: top;
}
.table.compact td, .table.compact th { padding: 0.3rem; font-size: 0.85rem; }
.table tr.checked { opacity: 0.5; }
.table-scroll { overflow-x: auto; -webkit-overflow-scrolling: touch; }

.stats {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(90px, 1fr));
  gap: 0.5rem;
  margin: 0.75rem 0;
}
.stats dt { color: var(--muted); font-size: 0.75rem; }
.stats dd { margin: 0.1rem 0 0; font-size: 1.15rem; font-weight: 700; }

.flashes { list-style: none; padding: 0; margin: 0 0 0.65rem; }
.flash { padding: 0.55rem 0.75rem; border-radius: 8px; margin-bottom: 0.35rem; font-size: 0.9rem; }
.flash-ok { background: #e5f6ee; }
.flash-error { background: #fde8e8; }

.progress-bar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 0.5rem;
  margin-bottom: 0.55rem;
  padding: 0.55rem 0.7rem;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
}
.sticky-top { position: sticky; top: 44px; z-index: 15; }
.progress-text { display: flex; flex-direction: column; gap: 0.05rem; }
.progress-text strong { font-size: 1.1rem; }

.finish-menu { position: relative; }
.finish-menu summary {
  list-style: none;
  cursor: pointer;
  min-width: 40px;
}
.finish-menu summary::-webkit-details-marker { display: none; }
.finish-menu[open] > form {
  position: absolute;
  right: 0;
  top: calc(100% + 4px);
  min-width: 160px;
  padding: 0.4rem;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  z-index: 30;
}

.page-work .wrap,
.page-count .wrap { padding: 0.5rem; max-width: 560px; }
.page-work .top .brand { font-size: 0.85rem; }

.loc-nav {
  display: grid;
  grid-template-columns: var(--touch) 1fr var(--touch);
  gap: 0.4rem;
  align-items: center;
  margin-bottom: 0.5rem;
}
.loc-nav-btn {
  font-size: 1.35rem;
  font-weight: 700;
  padding: 0;
  width: var(--touch);
  height: var(--touch);
}
.loc-current {
  text-align: center;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 0.4rem;
}
.loc-id { font-size: 1.35rem; font-weight: 800; line-height: 1.15; word-break: break-all; }
.loc-sub { font-size: 0.8rem; margin-top: 0.1rem; }

.locs-picker {
  margin-bottom: 0.5rem;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 0.2rem 0.55rem;
}
.locs-picker summary {
  cursor: pointer;
  padding: 0.45rem 0.1rem;
  font-weight: 600;
  font-size: 0.95rem;
  min-height: 40px;
  display: flex;
  align-items: center;
}
.locs-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem;
  padding: 0.25rem 0 0.55rem;
  max-height: 36vh;
  overflow: auto;
}
.chip {
  display: inline-flex;
  align-items: center;
  gap: 0.3rem;
  padding: 0.35rem 0.55rem;
  min-height: 36px;
  border-radius: 999px;
  border: 1px solid var(--line);
  background: #fff;
  text-decoration: none;
  color: var(--ink);
  font-size: 0.85rem;
}
.chip span { color: var(--muted); font-size: 0.75rem; }
.chip.active { background: #e5f0ea; border-color: var(--accent); font-weight: 700; }
.chip.done { opacity: 0.5; }

.scan-panel { margin-bottom: 0.5rem; }
.scan-form { display: flex; flex-direction: column; gap: 0.5rem; }
.scan-row { display: block; }
.scan-input {
  font-size: 1.2rem !important;
  font-weight: 600;
  padding: 0.85rem 0.75rem !important;
  min-height: 52px !important;
  width: 100%;
}

.item-cards { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 0.35rem; }
.item-card {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 0.55rem 0.65rem;
  background: #fff;
}
.item-card.checked { opacity: 0.5; }
.item-card-top { display: flex; align-items: flex-start; gap: 0.45rem; }
.item-status { font-size: 1rem; width: 1.1rem; text-align: center; line-height: 1.4; }
.item-main { flex: 1; min-width: 0; }
.item-main strong { font-size: 0.95rem; word-break: break-word; }
.item-name { color: var(--muted); font-size: 0.8rem; margin-top: 0.15rem; }
.item-qtys { display: flex; flex-direction: column; align-items: flex-end; gap: 0.2rem; flex-shrink: 0; }
.sys-pill, .fact-pill {
  font-weight: 700;
  font-size: 0.85rem;
  padding: 0.1rem 0.45rem;
  border-radius: 999px;
}
.sys-pill { background: #f0ebe3; color: var(--muted); }
.fact-pill { background: #e5f0ea; color: var(--accent); }
.desktop-only { display: none; }

.count-panel .back {
  display: inline-block;
  margin-bottom: 0.65rem;
  color: var(--accent);
  text-decoration: none;
  font-size: 0.95rem;
}
.count-title { margin: 0 0 0.35rem; font-size: 1.25rem; word-break: break-word; }
.desc { font-size: 0.95rem; margin: 0 0 0.65rem; color: var(--muted); }
.code-box {
  font-family: ui-monospace, monospace;
  font-size: 1.1rem;
  font-weight: 700;
  background: #f0ebe3;
  padding: 0.55rem 0.65rem;
  border-radius: 8px;
  word-break: break-all;
  margin: 0 0 0.75rem;
}
.count-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 0.75rem 1.25rem;
  margin: 0 0 0.75rem;
  font-size: 0.95rem;
}
.warn {
  background: var(--warn-bg);
  border: 1px solid #e6d08a;
  padding: 0.65rem 0.75rem;
  border-radius: 8px;
  margin: 0 0 0.75rem;
  font-size: 0.9rem;
}
.qty-label { font-weight: 700; }
.qty-stepper {
  display: grid;
  grid-template-columns: var(--touch) 1fr var(--touch);
  gap: 0.4rem;
}
.qty-btn {
  font-size: 1.5rem;
  font-weight: 700;
  padding: 0;
  min-height: 52px;
}
.qty-stepper input {
  text-align: center;
  font-size: 1.6rem !important;
  font-weight: 800;
  min-height: 52px;
  padding: 0.4rem;
}
.big-check {
  flex-direction: row !important;
  align-items: flex-start !important;
  gap: 0.55rem !important;
  padding: 0.65rem;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  font-weight: 600;
}
.big-check input { width: 1.25rem; height: 1.25rem; min-height: 0; flex-shrink: 0; }
.check { flex-direction: row !important; align-items: center; gap: 0.5rem !important; }

.neg { color: var(--err); font-weight: 600; }
.pos { color: var(--ok); font-weight: 600; }
.err { color: var(--err); font-size: 0.85rem; margin-bottom: 0.35rem; }
.inline-form { display: flex; gap: 0.4rem; flex-wrap: wrap; align-items: center; }
.badge { font-size: 0.85rem; color: var(--muted); }
.ops { padding-left: 1.1rem; }

.inv-cards { list-style: none; margin: 0; padding: 0; display: none; flex-direction: column; gap: 0.45rem; }
.inv-card {
  display: block;
  text-decoration: none;
  color: inherit;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 0.75rem 0.85rem;
  background: #fff;
}
.inv-card strong { display: block; margin-bottom: 0.2rem; }
.inv-card .meta-line { color: var(--muted); font-size: 0.85rem; }

@media (max-width: 800px) {
  .inv-table { display: none; }
  .inv-cards { display: flex; }
  .row.between h1 { font-size: 1.15rem; margin: 0; }
  .stats { grid-template-columns: repeat(2, 1fr); }
  .stack { max-width: none; }
}

@media (min-width: 801px) {
  .desktop-only { display: block; }
  .item-cards { display: none; }
  .locs-picker { display: none; }
  .finish-menu { display: none; }
  .finish-bottom { margin-top: 0.75rem; }
  .page-work .wrap { max-width: 960px; padding: 1rem; }
  .loc-nav { max-width: 360px; }
}

@media (max-width: 360px) {
  :root { --touch: 44px; }
  .wrap { padding: 0.4rem; }
  .loc-id { font-size: 1.15rem; }
  .scan-input { font-size: 1.05rem !important; }
}

@media (max-height: 480px) and (orientation: landscape) {
  .sticky-top { position: static; }
  .item-cards { max-height: 28vh; overflow: auto; }
}
