:root {
  --bg: #f4f6f9;
  --card: #fff;
  --text: #1c2430;
  --muted: #748090;
  --line: #e3e7ed;
  --primary: #24425f;
  --primary-2: #34597d;
  --ok: #1e8e3e;
  --ok-bg: #e8f5ec;
  --warn: #b26a00;
  --warn-bg: #fff3dc;
  --bad: #c62828;
  --bad-bg: #fdecea;
  --stock: #2f6fb3;
  --stock-bg: #eaf2fb;
  --inv: #6a4bb5;
  --inv-bg: #f1ecfa;
  --radius: 12px;
}
* { box-sizing: border-box; }
html, body { margin: 0; background: var(--bg); color: var(--text);
  font: 15px/1.4 -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  -webkit-text-size-adjust: 100%; }
.hidden { display: none !important; }
.muted { color: var(--muted); }
.small { font-size: 12.5px; }
h1 { font-size: 22px; margin: 0 0 4px; }
h2 { font-size: 17px; margin: 0; }
h3 { font-size: 14px; margin: 0 0 8px; letter-spacing: .02em; }
button { font-family: inherit; }
.card { background: var(--card); border-radius: var(--radius); box-shadow: 0 1px 2px rgba(20,30,50,.08); padding: 14px; }
.error { color: var(--bad); background: var(--bad-bg); padding: 10px 12px; border-radius: 8px; margin-top: 12px; }

/* кнопки */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; border: 1px solid var(--line);
  background: #fff; color: var(--text); padding: 9px 13px; border-radius: 10px; font-size: 14.5px; cursor: pointer;
  user-select: none; -webkit-tap-highlight-color: transparent; }
.btn:hover { border-color: #c3cad5; }
.btn:disabled { opacity: .45; cursor: default; }
.btn.primary { background: var(--primary); border-color: var(--primary); color: #fff; }
.btn.primary:hover { background: var(--primary-2); }
.btn.primary:disabled { background: #9fb0c2; border-color: #9fb0c2; opacity: 1; }
.btn.big { padding: 13px 18px; font-size: 16.5px; font-weight: 600; }
.btn.wide { width: 100%; }
.btn.small { padding: 6px 10px; font-size: 13.5px; }
.btn.tiny { padding: 4px 9px; font-size: 12.5px; border-radius: 8px; color: #4a5565; background: #fafbfc; }
.btn.ok { background: var(--ok); border-color: var(--ok); color: #fff; }
.btn.danger { color: var(--bad); border-color: #f0c9c6; background: #fff; }
.btn.ghost { color: var(--muted); }
.icon-btn { background: none; border: 0; color: #fff; font-size: 19px; line-height: 1; cursor: pointer; padding: 6px 8px; opacity: .75; border-radius: 8px; }
.icon-btn:hover { opacity: 1; background: rgba(255,255,255,.12); }
.icon-btn.dark { color: var(--text); }
.icon-btn.dark:hover { background: #eef1f5; }
input, select { font: inherit; }
input:not([type=checkbox]), select { width: 100%; border: 1px solid #cfd6df; border-radius: 8px; padding: 7px 9px; background: #fff; color: var(--text); }
input:focus, select:focus { outline: 2px solid #9db8d6; border-color: #9db8d6; }

/* вход */
#view-login { min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 16px; }
.login-card { width: 100%; max-width: 360px; display: flex; flex-direction: column; gap: 12px; padding: 22px; }
.login-card label { display: flex; flex-direction: column; gap: 4px; font-size: 13px; color: var(--muted); }
.login-card input { font-size: 16px; padding: 10px 12px; }

/* шапка */
.topbar { position: sticky; top: 0; z-index: 20; display: flex; align-items: center; justify-content: space-between;
  gap: 8px; padding: 8px 12px; padding-top: calc(8px + env(safe-area-inset-top)); background: var(--primary); color: #fff; }
.brand { background: none; border: 0; color: #fff; font-size: 17px; font-weight: 700; cursor: pointer; padding: 6px 4px; }
.top-actions { display: flex; align-items: center; gap: 4px; }
.top-actions .btn.primary { background: #fff; color: var(--primary); border-color: #fff; font-weight: 600; }
.top-actions .btn.primary:hover { background: #e9eff6; }
.top-link { background: none; border: 0; color: #fff; font-size: 14.5px; cursor: pointer; padding: 8px 8px; opacity: .9; }
.top-link:hover { opacity: 1; text-decoration: underline; }
.page { max-width: 920px; margin: 0 auto; padding: 12px 12px 40px; }

/* загрузка */
.zones { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.zone { border-radius: var(--radius); padding: 12px; border: 2px dashed transparent; }
.zone-stock { background: var(--stock-bg); border-color: #c5daf0; }
.zone-inv { background: var(--inv-bg); border-color: #d9cdf0; }
.zone.drag { border-style: solid; }
.zone-head { display: flex; gap: 10px; align-items: center; margin-bottom: 8px; }
.step { width: 26px; height: 26px; border-radius: 50%; color: #fff; display: flex; align-items: center; justify-content: center; font-weight: 700; flex: none; }
.zone-stock .step { background: var(--stock); }
.zone-inv .step { background: var(--inv); }
.zone-stock h2 { color: var(--stock); }
.zone-inv h2 { color: var(--inv); }
.thumbs { display: flex; flex-wrap: wrap; gap: 8px; min-height: 6px; margin-bottom: 8px; }
.thumb { width: 78px; }
.thumb .im { position: relative; }
.thumb img { width: 78px; height: 78px; object-fit: cover; border-radius: 8px; display: block; background: #fff; }
.thumb button { position: absolute; top: 2px; right: 2px; width: 22px; height: 22px; border: 0; border-radius: 50%; background: rgba(0,0,0,.6); color: #fff; font-size: 12px; cursor: pointer; }
.thumb .t { font-size: 10px; color: var(--muted); text-align: center; margin-top: 2px; white-space: nowrap; }
.zone-actions { display: flex; gap: 8px; flex-wrap: wrap; }
.zone-actions .btn { flex: 1; }
.tips { margin: 10px 2px 12px; }
@media (max-width: 640px) { .zones { grid-template-columns: 1fr; } }

/* итоговая карточка */
.head { padding: 0; overflow: hidden; margin-bottom: 10px; border-left: 6px solid var(--ok); }
.head.s-bad { border-left-color: var(--bad); }
.head.s-warn { border-left-color: var(--warn); }
.head-top { display: flex; align-items: center; gap: 12px; padding: 12px 14px 8px; }
.head-icon { width: 34px; height: 34px; border-radius: 50%; display: flex; align-items: center; justify-content: center; color: #fff; font-weight: 800; font-size: 18px; flex: none; background: var(--ok); }
.s-bad .head-icon { background: var(--bad); }
.s-warn .head-icon { background: var(--warn); }
.head-text { display: flex; flex-direction: column; line-height: 1.25; }
.head-text b { font-size: 17px; }
.head-text span { font-size: 13px; color: var(--muted); }
.head-nums { display: grid; grid-template-columns: 1fr 1.25fr 1fr; gap: 8px; padding: 4px 14px 10px; }
.num-block { border-radius: 10px; padding: 7px 10px; background: #f6f7f9; }
.num-block.stock { background: var(--stock-bg); }
.num-block.inv { background: var(--inv-bg); }
.num-block.diff.ok { background: var(--ok-bg); }
.num-block.diff.bad { background: var(--bad-bg); }
.nl { font-size: 11.5px; color: var(--muted); }
.nv { font-size: 18px; font-weight: 700; white-space: nowrap; }
.num-block.diff.bad .nv { color: var(--bad); }
.num-block.diff.ok .nv { color: var(--ok); }
.nv.inputs { display: flex; gap: 4px; flex-wrap: wrap; }
.nv.inputs input { font-size: 16px; font-weight: 700; padding: 3px 6px; border-color: transparent; background: rgba(255,255,255,.7); min-width: 90px; }
.head-dates { display: flex; flex-wrap: wrap; align-items: center; gap: 6px 10px; padding: 8px 14px; border-top: 1px solid var(--line); font-size: 12.5px; }
.head-dates .dl { color: var(--muted); }
.dchip { display: inline-flex; align-items: center; gap: 5px; padding: 2px 6px 2px 8px; border-radius: 8px; font-size: 12px; }
.dchip.stock { background: var(--stock-bg); color: var(--stock); }
.dchip.inv { background: var(--inv-bg); color: var(--inv); }
.dchip input { width: auto; padding: 2px 4px; font-size: 13px; border-radius: 6px; }
.mini { background: none; border: 0; cursor: pointer; padding: 0 2px; font-size: 13px; }
.dstate.ok { color: var(--ok); }
.dstate.warn { color: var(--warn); font-weight: 600; }
.taken { margin-left: auto; font-size: 11px; color: #9aa4b1; }
.head-msgs { padding: 0 14px 10px; display: flex; flex-direction: column; gap: 4px; }
@media (max-width: 560px) {
  .head-nums { grid-template-columns: 1fr 1fr; }
  .num-block.inv { grid-column: 1 / -1; order: 3; }
  .taken { margin-left: 0; width: 100%; }
}

.msg { font-size: 13px; padding: 5px 9px; border-radius: 7px; background: #eef1f5; }
.msg.warn { background: var(--warn-bg); color: #7a4a00; }
.msg.error { background: var(--bad-bg); color: #9a1f1f; }
.msg.ok { background: var(--ok-bg); color: #17692e; }
#notices { display: flex; flex-direction: column; gap: 4px; margin-bottom: 8px; }

/* список позиций */
.toolbar { display: flex; align-items: center; justify-content: space-between; margin: 14px 2px 6px; }
.toolbar-title { font-weight: 700; font-size: 14px; }
.tools { display: flex; gap: 6px; }
.rows-head, .row-main { display: grid; grid-template-columns: minmax(170px, 2.3fr) 1fr 1fr .7fr 1fr 1fr .9fr; gap: 4px 8px; align-items: center; }
.rows-head { padding: 4px 12px; font-size: 11px; color: var(--muted); text-transform: uppercase; letter-spacing: .03em; }
.rows-head div:not(:first-child) { text-align: right; }
.rows-head .h-stock { color: var(--stock); }
.rows-head .h-inv { color: var(--inv); }
.sec { margin-bottom: 10px; background: var(--card); border-radius: var(--radius); box-shadow: 0 1px 2px rgba(20,30,50,.08); overflow: hidden; }
.sec-head { width: 100%; display: flex; align-items: center; gap: 8px; padding: 8px 12px; border: 0; background: #f7f8fa; text-align: left;
  font-size: 13.5px; font-weight: 700; color: var(--text); }
button.sec-head { cursor: pointer; }
.sec-head b { background: #e6e9ee; border-radius: 10px; padding: 0 8px; font-size: 12px; }
.sec-arrow { margin-left: auto; color: var(--muted); }
.sec-dot { width: 9px; height: 9px; border-radius: 50%; background: var(--ok); }
.sec-bad .sec-dot { background: var(--bad); }
.sec-warn .sec-dot { background: var(--warn); }
.sec-bad .sec-head { background: var(--bad-bg); color: var(--bad); }
.sec-warn .sec-head { background: var(--warn-bg); color: var(--warn); }
.sec-ok .sec-head { background: var(--ok-bg); color: var(--ok); }
.row { border-top: 1px solid var(--line); border-left: 4px solid transparent; }
.row.s-bad { border-left-color: var(--bad); }
.row.s-warn { border-left-color: var(--warn); }
.row.s-ok { border-left-color: #b7dfc2; }
.row-main { padding: 8px 12px 8px 8px; cursor: pointer; }
.row-main:hover { background: #fafbfc; }
.r-name { display: flex; align-items: center; gap: 8px; min-width: 0; }
.r-idx { flex: none; width: 22px; text-align: center; font-size: 11px; color: var(--muted); }
.r-title { display: flex; flex-direction: column; min-width: 0; line-height: 1.2; }
.r-title b { font-weight: 600; overflow-wrap: anywhere; }
.r-title .sub { font-size: 11.5px; color: var(--muted); }
.badge { margin-right: 4px; flex: none; font-size: 11px; font-weight: 700; padding: 2px 7px; border-radius: 9px; white-space: nowrap; }
.badge.bad { background: var(--bad); color: #fff; }
.badge.warn { background: var(--warn); color: #fff; }
.c { text-align: right; font-variant-numeric: tabular-nums; border-radius: 6px; padding: 2px 6px; }
.c .cl { display: none; }
.c.stock { background: var(--stock-bg); }
.c.inv { background: var(--inv-bg); }
.c.diff.nz .cv { color: var(--bad); font-weight: 700; }
.eq { color: var(--muted); font-size: 12px; }
.r-issue { grid-column: 1 / -1; font-size: 12.5px; padding: 4px 8px; border-radius: 6px; margin-left: 30px; }
.r-issue.bad { background: var(--bad-bg); color: #9a1f1f; }
.r-issue.warn { background: var(--warn-bg); color: #7a4a00; }
@media (max-width: 720px) {
  .rows-head { display: none; }
  .row-main { grid-template-columns: repeat(3, 1fr); padding-right: 8px; }
  .r-name { grid-column: 1 / -1; }
  .c { text-align: left; padding: 3px 7px; }
  .c .cl { display: block; font-size: 10.5px; color: var(--muted); }
  .r-issue { margin-left: 0; }
}

.row-detail { padding: 4px 12px 12px 12px; background: #fcfcfd; border-top: 1px dashed var(--line); display: flex; flex-direction: column; gap: 8px; }
.crops { display: grid; grid-template-columns: repeat(auto-fit, minmax(260px, 1fr)); gap: 8px; }
.crop { border-radius: 8px; overflow: hidden; cursor: zoom-in; border: 2px solid var(--line); }
.crop.stock { border-color: #bcd4ee; }
.crop.inv { border-color: #d3c5ee; }
.crop .cap { font-size: 11.5px; font-weight: 700; padding: 2px 8px; }
.crop.stock .cap { background: var(--stock-bg); color: var(--stock); }
.crop.inv .cap { background: var(--inv-bg); color: var(--inv); }
.crop canvas { width: 100%; display: block; background: #fff; }
.edit { display: grid; grid-template-columns: repeat(auto-fit, minmax(130px, 1fr)); gap: 8px; }
.edit label { display: flex; flex-direction: column; gap: 3px; font-size: 11.5px; padding: 6px 8px; border-radius: 8px; }
.edit label.stock { background: var(--stock-bg); color: var(--stock); }
.edit label.inv { background: var(--inv-bg); color: var(--inv); }
.weights { font-size: 13px; color: #394656; overflow-wrap: anywhere; }
.notes { margin: 0; padding-left: 18px; font-size: 12.5px; color: var(--muted); }
.detail-actions { display: flex; gap: 8px; flex-wrap: wrap; }

/* итог */
.final { margin-top: 12px; margin-bottom: 14px; }
.final table { width: 100%; border-collapse: collapse; font-size: 14px; margin-bottom: 6px; }
.final td { padding: 6px 4px; border-bottom: 1px solid var(--line); }
.final .num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
.final .ft-errors td { font-size: 13px; }
.diff-bad { color: var(--bad); font-weight: 700; }
.ft-totals tr.grand td { font-weight: 700; background: var(--stock-bg); }
.ft-totals tr.bad td { font-weight: 700; background: var(--bad-bg); }
.ft-totals tr.ok td { font-weight: 700; background: var(--ok-bg); }
.ft-note { margin-top: 4px; }

/* история */
.hist-top { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 8px; margin-bottom: 8px; }
.chips { display: flex; gap: 6px; flex-wrap: wrap; }
.chip { border: 1px solid var(--line); background: #fff; border-radius: 16px; padding: 4px 11px; font-size: 13px; cursor: pointer; color: var(--text); }
.chip b { color: var(--muted); font-weight: 600; margin-left: 2px; }
.chip.active { background: var(--primary); border-color: var(--primary); color: #fff; }
.chip.active b { color: #cfe0f0; }
#history { background: var(--card); border-radius: var(--radius); box-shadow: 0 1px 2px rgba(20,30,50,.08); overflow: hidden; }
.empty { padding: 20px; text-align: center; }
.h-item { display: flex; align-items: center; gap: 10px; padding: 8px 10px 8px 12px; border-top: 1px solid var(--line); cursor: pointer; }
.h-item:first-child { border-top: 0; }
.h-item:hover { background: #fafbfc; }
.h-dot { width: 10px; height: 10px; border-radius: 50%; background: var(--ok); flex: none; }
.cat-warn .h-dot { background: var(--warn); }
.cat-error .h-dot { background: var(--bad); }
.h-main { flex: 1; min-width: 0; line-height: 1.25; }
.h-date { font-weight: 600; font-size: 14.5px; }
.h-rows { font-weight: 400; font-size: 12px; margin-left: 4px; }
.h-warn { color: var(--warn); }
.h-sub { font-size: 11px; color: #9aa4b1; }
.h-res { text-align: right; line-height: 1.25; }
.h-status { font-size: 12.5px; color: var(--ok); font-weight: 600; }
.cat-warn .h-status { color: var(--warn); }
.cat-error .h-status { color: var(--bad); }
.h-sum { font-size: 12px; color: var(--muted); font-variant-numeric: tabular-nums; }
.h-del { background: none; border: 0; cursor: pointer; font-size: 15px; opacity: .35; padding: 6px; }
.h-del:hover { opacity: .9; }

/* окна */
.overlay { position: fixed; inset: 0; background: rgba(15,25,40,.55); z-index: 50; display: flex; align-items: center; justify-content: center; padding: 12px; }
.busy-card { text-align: center; padding: 24px 30px; display: flex; flex-direction: column; gap: 6px; align-items: center; }
.spinner { width: 34px; height: 34px; border: 4px solid #d9e1ea; border-top-color: var(--primary); border-radius: 50%; animation: spin 0.9s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
#settings { align-items: flex-start; justify-content: flex-end; padding: 0; }
.sheet { background: #fff; width: 100%; max-width: 440px; height: 100%; display: flex; flex-direction: column; box-shadow: -4px 0 20px rgba(0,0,0,.2); }
.sheet-head { display: flex; align-items: center; justify-content: space-between; padding: 10px 14px; padding-top: calc(10px + env(safe-area-inset-top)); border-bottom: 1px solid var(--line); }
.sheet-body { overflow-y: auto; padding: 4px 14px 24px; display: flex; flex-direction: column; gap: 4px; -webkit-overflow-scrolling: touch; }
.set-sec { padding: 12px 0; border-bottom: 1px solid var(--line); display: flex; flex-direction: column; gap: 8px; }
.check { display: flex; gap: 9px; align-items: flex-start; font-size: 14px; cursor: pointer; }
.check input { margin-top: 3px; width: 17px; height: 17px; flex: none; }
.hint { display: block; font-size: 11.5px; color: var(--muted); }
.inline { display: flex; align-items: flex-end; gap: 10px; flex-wrap: wrap; }
.inline label { display: flex; flex-direction: column; gap: 3px; font-size: 12px; color: var(--muted); flex: 1; min-width: 160px; }
.btn-col { display: flex; flex-direction: column; gap: 6px; }
.btn-row { display: flex; gap: 8px; align-items: center; justify-content: space-between; flex-wrap: wrap; }
.clean-grid { display: flex; flex-direction: column; gap: 6px; }
.clean-grid label { display: grid; grid-template-columns: 1fr 150px; gap: 8px; align-items: center; font-size: 14px; }
.clean-grid .dot { display: inline-block; width: 9px; height: 9px; border-radius: 50%; margin-right: 7px; background: var(--ok); }
.clean-grid .dot.warn { background: var(--warn); }
.clean-grid .dot.bad { background: var(--bad); }
.sys-row { display: flex; justify-content: space-between; gap: 8px; font-size: 13px; color: var(--text); margin-top: 4px; }
.sys-row span { color: var(--muted); }
.bar { height: 6px; background: #e8ecf1; border-radius: 4px; overflow: hidden; margin: 2px 0; }
.bar i { display: block; height: 100%; background: var(--ok); }
.bar i.warn { background: var(--warn); }
.bar i.bad { background: var(--bad); }
.photo-wrap { position: relative; max-width: 960px; width: 100%; max-height: 100%; overflow: auto; background: #111; border-radius: 10px; }
.photo-wrap canvas { width: 100%; display: block; }
.photo-wrap .close { position: sticky; top: 8px; float: right; margin: 8px; z-index: 2; }
.toast { position: fixed; left: 50%; bottom: calc(18px + env(safe-area-inset-bottom)); transform: translateX(-50%); background: #26303c; color: #fff;
  padding: 10px 16px; border-radius: 10px; font-size: 14px; z-index: 80; max-width: 92vw; text-align: center; box-shadow: 0 4px 16px rgba(0,0,0,.3); }

/* печать: только отчёт */
@media print {
  body { background: #fff; }
  .topbar, .toolbar, #btn-new-bottom, .overlay, .toast, .detail-actions, .crops, .edit, .mini { display: none !important; }
  .page { max-width: none; padding: 0; }
  .card, .sec, #history { box-shadow: none; }
  .row-detail { display: none; }
  .sec, .row { break-inside: avoid; }
  .taken { color: #666; }
}

/* раскрытая строка отделена от соседних */
.row.open { margin: 8px 0; border-top: 2px solid #dfe4ea; border-bottom: 2px solid #dfe4ea; background: #fcfcfd; }
.row.open + .row { border-top: 0; }
.row.flash { animation: flash 1.6s ease-out; }
@keyframes flash { 0%, 40% { box-shadow: 0 0 0 3px rgba(36,66,95,.45); } 100% { box-shadow: 0 0 0 0 rgba(36,66,95,0); } }
.row-detail { border-top: 1px dashed var(--line); }

/* итоговая таблица */
.ft-errors tr.jump { cursor: pointer; }
.ft-errors tr.jump:hover td { background: #f3f6fa; }
.ft-errors tr.jump td:first-child { color: var(--primary); text-decoration: underline dotted; }
.ft-totals tr.strong td { font-weight: 700; font-size: 15.5px; }

/* кнопка «Следующая проверка» в идеальном результате */
.btn.primary.next-top { width: 100%; margin: 2px 0 6px; padding: 11px 16px; font-weight: 600; background: var(--ok); border-color: var(--ok); }
.btn.primary.next-top:hover { background: #197a35; }
@media (min-width: 721px) { .next-top { width: auto; } }

/* картинка отчёта */
.iv-box { width: 100%; max-width: 560px; max-height: 100%; display: flex; flex-direction: column; gap: 8px; }
.iv-head { display: flex; align-items: center; justify-content: space-between; }
.iv-actions { display: flex; gap: 6px; flex-wrap: wrap; }
.iv-scroll { overflow: auto; border: 1px solid var(--line); border-radius: 8px; min-height: 120px; -webkit-touch-callout: default; }
.iv-scroll img { width: 100%; display: block; -webkit-user-select: auto; user-select: auto; }
.row { scroll-margin-top: 70px; }
