/* stock-count.css — หน้านับสต๊อก (มือถือก่อน ใช้กับเครื่องยิงบาร์โค้ดได้) */
:root {
  --bg: #f1f5f9; --card: #fff; --ink: #0f172a; --muted: #64748b; --line: #e2e8f0;
  --primary: #2563eb; --primary-dark: #1d4ed8; --ok: #059669; --ok-bg: #ecfdf5;
  --bad: #dc2626; --bad-bg: #fef2f2; --warn: #b45309; --warn-bg: #fffbeb; --over: #7c3aed; --over-bg: #f5f3ff;
}
* { box-sizing: border-box; }
html, body { margin: 0; background: var(--bg); color: var(--ink);
  font-family: "Sarabun", "Noto Sans Thai", "Leelawadee UI", "Segoe UI", system-ui, sans-serif; font-size: 16px; }
.hidden { display: none !important; }
button, input, select { font: inherit; }

.bar { position: sticky; top: 0; z-index: 5; display: flex; align-items: center; gap: 10px;
  padding: 10px 12px; padding-top: max(10px, env(safe-area-inset-top)); background: #0f172a; color: #fff; }
.bar h1 { margin: 0; font-size: 17px; line-height: 1.2; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.bar-title { flex: 1; min-width: 0; }
.bar-title span { display: block; font-size: 12.5px; color: #94a3b8; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.back { color: #cbd5e1; background: none; border: 0; padding: 6px 4px; text-decoration: none; font-size: 15px; cursor: pointer; white-space: nowrap; }
.sync { font-size: 12px; padding: 4px 9px; border-radius: 999px; background: #1e293b; color: #cbd5e1; white-space: nowrap; }
.sync.ok { background: #064e3b; color: #a7f3d0; }
.sync.wait { background: #78350f; color: #fde68a; }
.sync.off { background: #7f1d1d; color: #fecaca; }

/* Bar + tabs move together, so the tabs never slide under a taller bar (notch, long title). */
.sticky-head { position: sticky; top: 0; z-index: 5; }
.sticky-head .bar { position: static; }
.tabs { display: flex; background: #fff; border-bottom: 1px solid var(--line); }
.tabs button { flex: 1; border: 0; background: none; padding: 12px; font-weight: 700; color: var(--muted); border-bottom: 3px solid transparent; cursor: pointer; }
.tabs button.active { color: var(--primary); border-bottom-color: var(--primary); }

.page { max-width: 760px; margin: 0 auto; padding: 14px 12px 40px; }
.card { background: var(--card); border: 1px solid var(--line); border-radius: 14px; padding: 14px; margin-bottom: 14px; }
.card h2 { margin: 0 0 10px; font-size: 17px; }
.center-card { max-width: 360px; margin: 18vh auto 0; text-align: center; background: #fff; border-radius: 16px; padding: 28px 20px; border: 1px solid var(--line); }
h2.section { font-size: 15px; color: var(--muted); margin: 18px 2px 8px; }
h3 { font-size: 14px; color: var(--muted); margin: 18px 2px 8px; }
label { display: block; font-size: 13px; color: var(--muted); margin-bottom: 10px; }
label input, label select { display: block; width: 100%; margin-top: 4px; padding: 10px 11px; border: 1px solid #cbd5e1; border-radius: 10px; background: #fff; color: var(--ink); }
.row { display: flex; gap: 10px; flex-wrap: wrap; align-items: flex-end; }
.grow { flex: 1 1 150px; }
.hint { font-size: 13px; color: var(--muted); margin: 8px 2px 0; }
.hint.warn { color: var(--warn); }

.btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; border-radius: 10px; padding: 11px 16px; border: 1px solid transparent; font-weight: 700; cursor: pointer; text-decoration: none; }
.btn.primary { background: var(--primary); color: #fff; }
.btn.primary:active { background: var(--primary-dark); }
.btn.ghost { background: #fff; color: var(--ink); border-color: #cbd5e1; }
.btn.danger { background: #fff; color: var(--bad); border-color: #fca5a5; }
.btn.small { padding: 7px 11px; font-size: 13.5px; }
.btn.wide { width: 100%; }
.btn:disabled { opacity: .5; cursor: default; }

.list { display: grid; gap: 8px; }
.branch-tabs { display: flex; flex-wrap: wrap; gap: 8px; padding: 2px 0 12px; }
.branch-tabs button { flex: none; border: 1px solid #cbd5e1; background: #fff; color: var(--ink); border-radius: 999px; padding: 9px 14px; font-weight: 700; cursor: pointer; white-space: nowrap; }
.branch-tabs button.active { background: var(--primary); border-color: var(--primary); color: #fff; }
.branch-tabs button small { font-weight: 600; opacity: .8; margin-left: 4px; }
.count-row { display: flex; align-items: center; gap: 10px; background: #fff; border: 1px solid var(--line); border-radius: 12px; padding: 12px; cursor: pointer; text-align: left; width: 100%; }
.count-row b { display: block; }
.count-row small { color: var(--muted); }
.count-row .grow { flex: 1; min-width: 0; }
.chip { font-size: 12px; font-weight: 700; padding: 3px 9px; border-radius: 999px; white-space: nowrap; }
.chip.open { background: var(--ok-bg); color: var(--ok); }
.chip.closed { background: #f1f5f9; color: var(--muted); }

.banner { border-radius: 12px; padding: 10px 12px; margin-bottom: 12px; font-size: 14px; }
.banner.danger { background: var(--bad-bg); color: var(--bad); }
.banner.warn { background: var(--warn-bg); color: var(--warn); }
.banner button { margin-left: 8px; }

.scan-input { width: 100%; font-size: 22px; padding: 16px 14px; border: 2px solid var(--primary); border-radius: 14px; background: #fff; letter-spacing: .5px; }
.scan-input:focus { outline: 4px solid rgba(37,99,235,.18); }
.qty-row { display: flex; align-items: center; gap: 8px; margin: 10px 0 12px; flex-wrap: wrap; }
.qty-label { font-size: 13.5px; color: var(--muted); }
.qty-row input { width: 84px; text-align: center; padding: 9px 6px; border: 1px solid #cbd5e1; border-radius: 10px; font-size: 18px; }
.step { width: 42px; height: 42px; border-radius: 10px; border: 1px solid #cbd5e1; background: #fff; font-size: 22px; cursor: pointer; }
#btn-keyboard { margin-left: auto; }

.last-card { border-radius: 16px; padding: 16px; min-height: 96px; display: grid; gap: 4px; align-content: center; border: 2px solid var(--line); background: #fff; }
.last-card b { font-size: 19px; line-height: 1.3; }
.last-card span { font-size: 15px; color: var(--muted); }
.last-card .big { font-size: 30px; font-weight: 800; color: var(--ink); }
.last-card.ok { border-color: #6ee7b7; background: var(--ok-bg); }
.last-card.pending { border-color: #fcd34d; background: var(--warn-bg); }
.last-card.bad { border-color: #fca5a5; background: var(--bad-bg); }
.last-card.bad b { color: var(--bad); }

.device-bar { display: flex; align-items: center; gap: 10px; background: #eef2ff; border: 1px solid #c7d2fe; color: #1e1b4b; border-radius: 12px; padding: 10px 12px; margin-bottom: 10px; }
.device-bar b { font-size: 17px; margin-left: 4px; }
.device-bar small { display: block; color: #4338ca; font-size: 13px; }
.device-dot { width: 12px; height: 12px; border-radius: 50%; background: #4f46e5; flex: none; }
h3 small { font-weight: 500; font-size: 12px; }
.thumb { width: 52px; height: 52px; border-radius: 10px; object-fit: cover; background: #f1f5f9; border: 1px solid var(--line); flex: none; display: grid; place-items: center; color: #94a3b8; font-size: 11px; }
.last-card.with-img { grid-template-columns: 84px 1fr; column-gap: 14px; align-items: center; }
.last-card.with-img .thumb { width: 84px; height: 84px; grid-row: span 4; }
.last-card .code { font-size: 14px; color: var(--muted); letter-spacing: .3px; }
.recent .code { display: block; font-size: 12.5px; color: #475569; letter-spacing: .3px; }
.photo-btn { position: relative; padding: 0; border: 0; background: none; cursor: pointer; flex: none; }
.photo-btn .thumb { border: 2px dashed #a5b4fc; }
.photo-btn .thumb.has-photo { border: 2px solid #4f46e5; }
.photo-btn .cam { position: absolute; right: -4px; bottom: -4px; background: #4f46e5; color: #fff; border-radius: 999px; font-size: 11px; padding: 2px 6px; font-weight: 700; }
.photo-btn.busy { opacity: .5; }
.last-card.with-img .photo-btn { grid-row: span 4; }
.last-card.with-img .photo-btn .thumb { width: 84px; height: 84px; }
.photos { display: flex; gap: 6px; flex-wrap: wrap; }
.photos-label { font-size: 12.5px; color: var(--muted); margin-bottom: -2px; }
.photos a img { width: 96px; height: 96px; object-fit: cover; border-radius: 8px; border: 1px solid var(--line); }
.devices { grid-column: 1 / -1; background: #fff; border: 1px solid var(--line); border-radius: 12px; padding: 10px 12px; margin-bottom: 12px; font-size: 14px; }
.devices b { display: block; margin-bottom: 4px; font-size: 13px; color: var(--muted); }
.devices div { display: flex; justify-content: space-between; gap: 10px; padding: 3px 0; border-top: 1px dashed var(--line); }
.devices div:first-of-type { border-top: 0; }
.recent { list-style: none; margin: 0; padding: 0; display: grid; gap: 6px; }
.recent li { display: flex; align-items: center; gap: 10px; background: #fff; border: 1px solid var(--line); border-radius: 10px; padding: 9px 10px; min-width: 0; max-width: 100%; }
.recent .grow { flex: 1; min-width: 0; }
.recent .name { display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; font-weight: 600; line-height: 1.3; word-break: break-word; }
.recent small { color: var(--muted); }
.recent .qty { font-weight: 800; white-space: nowrap; }
.recent li.unknown { border-color: #fca5a5; background: var(--bad-bg); }
.recent li.pending { border-color: #fcd34d; }
.recent li.voided { opacity: .5; text-decoration: line-through; }
.recent button { border: 0; background: none; color: var(--bad); font-weight: 700; padding: 6px; cursor: pointer; }
/* "ลบ": big enough for a finger (44 px), it asks before deleting. */
.recent .void-btn { min-width: 44px; min-height: 44px; padding: 8px 10px; border: 1px solid #fecaca; border-radius: 10px; background: #fff; flex: none; }

.stats { display: grid; grid-template-columns: repeat(auto-fill, minmax(104px, 1fr)); gap: 8px; margin-bottom: 12px; }
.stat { background: #fff; border: 1px solid var(--line); border-radius: 12px; padding: 10px; }
.stat b { display: block; font-size: 22px; }
.stat span { font-size: 12.5px; color: var(--muted); }
.stat.bad b { color: var(--bad); } .stat.over b { color: var(--over); } .stat.ok b { color: var(--ok); } .stat.warn b { color: var(--warn); }
.filters select, .filters input { padding: 9px 10px; border: 1px solid #cbd5e1; border-radius: 10px; background: #fff; }
.filters input { flex: 1 1 140px; }

.item { background: #fff; border: 1px solid var(--line); border-left: 5px solid #cbd5e1; border-radius: 12px; padding: 10px 12px; display: grid; gap: 6px; }
.item.neg { border-left-color: var(--bad); }
.item.pos { border-left-color: var(--over); }
.item.zero { border-left-color: var(--ok); }
.item-head { display: flex; gap: 8px; align-items: flex-start; }
.item-head .grow { flex: 1; min-width: 0; }
.item-head b { display: block; }
.item-head small { color: var(--muted); word-break: break-all; }
.nums { display: flex; gap: 14px; flex-wrap: wrap; font-size: 14px; color: var(--muted); }
.nums b { color: var(--ink); font-size: 16px; }
.diff { font-weight: 800; font-size: 18px; white-space: nowrap; }
.diff.neg { color: var(--bad); } .diff.pos { color: var(--over); } .diff.zero { color: var(--ok); }
.flag { font-size: 12.5px; color: var(--warn); background: var(--warn-bg); border-radius: 8px; padding: 4px 8px; }
.item button { justify-self: start; }

.report-actions { background: #fff; border-bottom: 1px solid var(--line); padding: 8px 12px; display: flex; flex-wrap: wrap; gap: 8px; align-items: center; justify-content: space-between; }
.report-actions .actions-main, .report-actions .actions-side { display: flex; flex-wrap: wrap; gap: 6px; }
/* "ปิดรอบนับ" sits apart on the right, with a divider, so it is not hit by mistake. */
.report-actions .actions-side { padding-left: 10px; border-left: 1px solid var(--line); }
.report-actions .hint { flex-basis: 100%; margin: 0; font-size: 12px; }
.report-actions .btn.small { padding: 6px 10px; font-size: 13px; border-radius: 9px; }
/* Phones: all buttons flow in one wrapping group; "ปิดรอบนับ" keeps its divider. */
@media (max-width: 480px) {
  .report-actions { padding: 6px 10px; gap: 6px; justify-content: flex-start; }
  .report-actions .actions-main { display: contents; }
  .report-actions .actions-side { padding-left: 6px; margin-left: auto; }
}
@media (min-width: 760px) { .report-actions { padding-left: calc((100% - 736px) / 2); padding-right: calc((100% - 736px) / 2); } }
.help p { margin: 6px 0 0; font-size: 14px; color: #334155; line-height: 1.55; }

/* Top of the screen: the phone keyboard covers the bottom while scanning. */
.toast { position: fixed; left: 50%; top: calc(env(safe-area-inset-top) + 64px); transform: translateX(-50%); background: #0f172a; color: #fff; padding: 10px 16px; border-radius: 12px; font-size: 14px; z-index: 40; max-width: 92vw; box-shadow: 0 6px 20px rgba(15,23,42,.25); }
.btn.busy { position: relative; opacity: .7; cursor: progress; }
.chip.pending { background: var(--warn-bg); color: var(--warn); }
.banner .codes { margin: 6px 0 0; padding-left: 18px; font-size: 13px; color: #334155; }
@media (min-width: 720px) { .scan-input { font-size: 26px; } }

/* ─── Audit workflow (scope, progress, recount, damages, close, approval) ─── */
.field-label { font-size: 13px; color: var(--muted); margin: 4px 2px 6px; }
.seg { display: flex; gap: 6px; margin-bottom: 8px; }
.seg-btn { flex: 1; min-height: 46px; border: 1px solid #cbd5e1; background: #fff; color: var(--ink); border-radius: 10px; font-weight: 700; cursor: pointer; padding: 8px 6px; }
.seg-btn.active { background: var(--primary); border-color: var(--primary); color: #fff; }
.chips { display: flex; flex-wrap: wrap; gap: 8px; margin: 4px 0 12px; }
.chip-toggle { min-height: 42px; border: 1px solid #cbd5e1; background: #fff; color: var(--ink); border-radius: 999px; padding: 8px 14px; font-weight: 600; cursor: pointer; }
.chip-toggle small { color: var(--muted); font-weight: 600; margin-left: 2px; }
.chip-toggle.on { background: #eff6ff; border-color: var(--primary); color: var(--primary-dark); }
.chip-toggle.on::before { content: '✓ '; }
.chip-toggle:disabled { opacity: .45; cursor: default; }
label.check { display: flex; align-items: flex-start; gap: 10px; font-size: 14.5px; color: var(--ink); padding: 6px 2px; cursor: pointer; }
label.check input { width: 22px; height: 22px; margin: 1px 0 0; flex: none; }
label.check small { color: var(--muted); }
.chips-col { display: flex; flex-direction: column; align-items: flex-end; gap: 4px; }
.chip.approved { background: var(--ok-bg); color: var(--ok); }
.chip.rejected { background: var(--bad-bg); color: var(--bad); }
.banner.info { background: #eef2ff; color: #3730a3; }
.banner.ok { background: var(--ok-bg); color: var(--ok); }
.damage-btn { margin-top: 10px; min-height: 48px; border-style: dashed; color: var(--warn); border-color: #fcd34d; }

.progress-card { background: #fff; border: 1px solid var(--line); border-radius: 14px; padding: 12px 14px; margin-bottom: 12px; }
.progress-head { display: flex; justify-content: space-between; align-items: baseline; gap: 10px; }
.progress-head b { font-size: 16px; }
.big-pct { font-size: 22px; font-weight: 800; color: var(--primary); }
.track { height: 12px; background: #e2e8f0; border-radius: 999px; overflow: hidden; margin: 8px 0 6px; }
.track .fill { height: 100%; background: var(--primary); border-radius: 999px; }
.progress-sub { font-size: 13.5px; color: var(--muted); }
.progress-card details { margin-top: 8px; }
.progress-card summary { cursor: pointer; font-weight: 700; color: var(--primary); padding: 8px 0; min-height: 40px; }
.mini { margin: 8px 0; overflow-x: auto; }
.mini b { display: block; font-size: 13px; color: var(--muted); margin-bottom: 4px; }
.mini table { width: 100%; border-collapse: collapse; font-size: 13.5px; }
.mini th, .mini td { text-align: right; padding: 5px 6px; border-bottom: 1px solid var(--line); white-space: nowrap; }
.mini th:first-child, .mini td:first-child { text-align: left; white-space: normal; }
.mini th { color: var(--muted); font-weight: 600; }
.totals { display: grid; grid-template-columns: repeat(auto-fill, minmax(104px, 1fr)); gap: 8px; margin-bottom: 12px; }
.totals .stat b { font-size: 18px; }
.totals-title { grid-column: 1 / -1; font-size: 13px; color: var(--muted); }

.badges { display: flex; flex-wrap: wrap; gap: 6px; }
.badge { font-size: 12.5px; font-weight: 700; padding: 3px 9px; border-radius: 999px; background: #f1f5f9; color: var(--muted); }
.badge.warn { background: var(--warn-bg); color: var(--warn); }
.badge.pending { background: #fef3c7; color: #92400e; }
.badge.ok { background: var(--ok-bg); color: var(--ok); }
.note { font-size: 13.5px; color: #334155; background: #f8fafc; border-radius: 8px; padding: 5px 8px; word-break: break-word; }
.item-actions { display: flex; flex-wrap: wrap; gap: 8px; }
.item-actions .btn.small { min-height: 40px; }
.btn.warn-btn { background: var(--warn-bg); color: var(--warn); border-color: #fcd34d; }
.item.voided { opacity: .55; }
.item.voided .grow b { text-decoration: line-through; }
.list-head { display: flex; flex-wrap: wrap; align-items: center; gap: 10px; justify-content: space-between; }
.hint.strong { color: var(--ink); font-weight: 600; }
.pager { display: flex; align-items: center; justify-content: center; gap: 12px; margin: 12px 0; font-size: 14px; color: var(--muted); }
.pager .btn { min-height: 42px; }
.log-row { background: #fff; border: 1px solid var(--line); border-radius: 10px; padding: 8px 12px; display: grid; gap: 2px; font-size: 14px; }
.log-head { display: flex; justify-content: space-between; gap: 10px; }
.log-head span { color: var(--muted); font-size: 12.5px; white-space: nowrap; }
.log-row small { color: #475569; word-break: break-word; }
.log-row .who { color: var(--muted); }
.thresholds b { display: block; }
.thresholds .row { margin-top: 8px; }

/* Forms on top of the page: a sheet from the bottom on phones, a card on wide screens. */
.overlay { position: fixed; inset: 0; z-index: 30; background: rgba(15,23,42,.55); display: flex; align-items: flex-end; justify-content: center; }
.sheet { background: #fff; width: 100%; max-width: 560px; max-height: 92vh; overflow-y: auto; border-radius: 18px 18px 0 0; padding: 16px 16px max(16px, env(safe-area-inset-bottom)); }
.sheet h2 { margin: 0 0 8px; font-size: 18px; }
.sheet-body p, .sheet-body li { font-size: 14px; margin: 4px 0; color: #334155; }
.sheet-body ul { margin: 4px 0; padding-left: 20px; }
.warn-text { color: var(--bad) !important; font-weight: 700; }
.policy-numbers { font-weight: 700; font-size: 15px; margin: 10px 0 8px; }
.choice { display: grid; gap: 3px; width: 100%; text-align: left; border: 2px solid #cbd5e1; background: #fff; border-radius: 12px; padding: 12px 14px; margin-bottom: 8px; cursor: pointer; min-height: 56px; }
.choice b { font-size: 15.5px; color: var(--ink); }
.choice span { font-size: 13px; color: var(--muted); }
.choice.active { border-color: var(--primary); background: #eff6ff; }
.choice.active b::before { content: '● '; color: var(--primary); }
.choice:disabled { opacity: .45; cursor: default; }
.sheet-actions { display: flex; gap: 10px; margin-top: 14px; }
.sheet-actions .btn { flex: 1; min-height: 50px; font-size: 16px; }
.btn.danger-fill { background: var(--bad); color: #fff; }
.photo-row { align-items: center; margin-bottom: 6px; }
@media (min-width: 640px) { .overlay { align-items: center; } .sheet { border-radius: 18px; } }
