[hidden] { display: none !important; }

:root {
  --bg: #f4f6f9;
  --card: #ffffff;
  --text: #1f2937;
  --muted: #6b7280;
  --line: #e5e7eb;
  --primary: #1f4e78;
  --primary-2: #2d6aa3;
  --ok: #15803d;
  --ok-bg: #dcfce7;
  --warn: #b45309;
  --warn-bg: #fef3c7;
  --bad: #b91c1c;
  --bad-bg: #fee2e2;
  --info-bg: #dbeafe;
  --radius: 10px;
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  font-family: "Sarabun", "Noto Sans Thai", "Segoe UI", Tahoma, sans-serif;
  font-size: 15px;
  background: var(--bg);
  color: var(--text);
}
h1, h2, h3 { margin: 0; }
button, input, select { font: inherit; }
a { color: var(--primary-2); }

/* ── buttons / fields ───────────────────────────────────────── */
.btn {
  border: 1px solid var(--line);
  background: #fff;
  color: var(--text);
  padding: 8px 14px;
  border-radius: 8px;
  cursor: pointer;
  white-space: nowrap;
}
.btn:hover { background: #f9fafb; }
.btn:disabled { opacity: .5; cursor: default; }
.btn-primary { background: var(--primary); border-color: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-2); }
.btn-danger { color: var(--bad); border-color: #fca5a5; }
.btn-ok { background: var(--ok); border-color: var(--ok); color: #fff; }
.btn-block { width: 100%; }
.btn-lg { padding: 14px 18px; font-size: 18px; }
.btn-sm { padding: 4px 10px; font-size: 13px; }

.btn-group { display: inline-flex; }
.btn-group .btn { border-radius: 0; margin-left: -1px; }
.btn-group .btn:first-child { border-radius: 8px 0 0 8px; margin-left: 0; }
.btn-group .btn:last-child { border-radius: 0 8px 8px 0; }

.field { display: flex; flex-direction: column; gap: 4px; margin-bottom: 12px; }
.field label { font-size: 13px; color: var(--muted); }
.field input, .field select {
  padding: 9px 11px;
  border: 1px solid #d1d5db;
  border-radius: 8px;
  background: #fff;
}
.field-row { display: flex; gap: 12px; flex-wrap: wrap; }
.field-row .field { flex: 1 1 160px; }
.check { display: flex; align-items: center; gap: 8px; margin-bottom: 10px; }

/* ── login ──────────────────────────────────────────────────── */
.login-screen {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  background: linear-gradient(135deg, #1f4e78, #2d6aa3);
}
.login-card {
  width: 100%;
  max-width: 380px;
  background: #fff;
  border-radius: 14px;
  padding: 26px;
  box-shadow: 0 10px 30px rgba(0,0,0,.2);
}
.brand { display: flex; align-items: center; gap: 12px; margin-bottom: 20px; }
.brand-mark {
  width: 44px; height: 44px;
  border-radius: 10px;
  background: var(--primary);
  color: #fff;
  display: flex; align-items: center; justify-content: center;
  font-weight: 700;
}
.brand p { margin: 0; font-size: 12px; color: var(--muted); }
.error { color: var(--bad); font-size: 14px; margin: 8px 0 0; }

/* ── layout ─────────────────────────────────────────────────── */
.topbar {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; gap: 12px;
  padding: 10px 16px;
  background: var(--primary);
  color: #fff;
}
.topbar .brand-mark { background: #fff; color: var(--primary); width: 36px; height: 36px; }
.topbar .title { font-weight: 700; }
.topbar .sub { font-size: 12px; opacity: .85; }
.topbar .spacer { flex: 1; }
.topbar .btn { background: transparent; color: #fff; border-color: rgba(255,255,255,.4); }

.container { max-width: 1280px; margin: 0 auto; padding: 16px; }
.card {
  background: var(--card);
  border-radius: var(--radius);
  border: 1px solid var(--line);
  padding: 16px;
  margin-bottom: 16px;
}
.card-head { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; margin-bottom: 12px; }
.card-head h2 { font-size: 18px; }
.card-head .spacer { flex: 1; }
.muted { color: var(--muted); }
.nowrap { white-space: nowrap; }
.small { font-size: 13px; }

/* ── KPI ────────────────────────────────────────────────────── */
.kpis { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 12px; margin-bottom: 16px; }
.kpi { background: #fff; border: 1px solid var(--line); border-radius: var(--radius); padding: 12px 14px; }
.kpi .label { font-size: 12px; color: var(--muted); }
.kpi .value { font-size: 22px; font-weight: 700; margin-top: 2px; }
.kpi.bad .value { color: var(--bad); }
.kpi.ok .value { color: var(--ok); }
.kpi.warn .value { color: var(--warn); }

.progress { height: 8px; background: #e5e7eb; border-radius: 99px; overflow: hidden; }
.progress > div { height: 100%; background: var(--ok); }

/* ── tables (sticky header: bounded wrapper) ────────────────── */
.table-wrap { max-height: 65vh; overflow: auto; border: 1px solid var(--line); border-radius: 8px; }
table { width: 100%; border-collapse: collapse; font-size: 14px; }
th, td { padding: 7px 9px; border-bottom: 1px solid var(--line); text-align: left; vertical-align: top; }
th { position: sticky; top: 0; background: #f3f4f6; z-index: 1; font-weight: 600; white-space: nowrap; }
td.num, th.num { text-align: right; white-space: nowrap; }
tr.clickable { cursor: pointer; }
tr.clickable:hover td { background: #f9fafb; }

/* ── badges ─────────────────────────────────────────────────── */
.badge { display: inline-block; padding: 2px 8px; border-radius: 99px; font-size: 12px; white-space: nowrap; background: #f3f4f6; }
.st-UNCOUNTED { background: #f3f4f6; color: var(--muted); }
.st-MATCH, .st-CLOSED { background: var(--ok-bg); color: var(--ok); }
.st-WITHIN, .st-COUNTED, .st-COUNTING { background: var(--info-bg); color: var(--primary); }
.st-RECOUNT { background: var(--bad-bg); color: var(--bad); }
.st-RECOUNTED, .st-REVIEW { background: var(--warn-bg); color: var(--warn); }
.st-CANCELLED { background: #e5e7eb; color: var(--muted); text-decoration: line-through; }
.pos { color: var(--ok); }
.neg { color: var(--bad); }

.pin { font-family: Consolas, monospace; font-size: 20px; font-weight: 700; letter-spacing: 3px; }
.qr { width: 120px; height: 120px; }
.qr img, .qr canvas { width: 120px !important; height: 120px !important; }
.team-cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 12px; }
.team-card { border: 1px solid var(--line); border-radius: var(--radius); padding: 12px; display: flex; gap: 12px; }
.team-card .info { flex: 1; min-width: 0; }

.toolbar { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; margin-bottom: 10px; }
.toolbar input, .toolbar select { padding: 7px 10px; border: 1px solid #d1d5db; border-radius: 8px; background: #fff; }

/* ── modal ──────────────────────────────────────────────────── */
.modal-back {
  position: fixed; inset: 0; z-index: 50;
  background: rgba(0,0,0,.45);
  display: flex; align-items: flex-end; justify-content: center;
}
.modal {
  background: #fff;
  width: 100%; max-width: 520px;
  max-height: 92vh; overflow: auto;
  border-radius: 16px 16px 0 0;
  padding: 18px;
}
@media (min-width: 640px) {
  .modal-back { align-items: center; }
  .modal { border-radius: 16px; }
}
.modal h3 { margin-bottom: 4px; }
.modal-actions { display: flex; gap: 10px; margin-top: 14px; }
.modal-actions .btn { flex: 1; }

.notice {
  position: fixed; left: 50%; bottom: 20px; transform: translateX(-50%);
  z-index: 60;
  padding: 10px 16px; border-radius: 8px;
  background: #111827; color: #fff;
  box-shadow: 0 6px 20px rgba(0,0,0,.25);
  max-width: calc(100% - 32px);
}
.notice-error { background: var(--bad); }
.notice-ok { background: var(--ok); }

/* ── counter (mobile) ───────────────────────────────────────── */
.scanbar {
  position: sticky; top: 56px; z-index: 15;
  background: var(--bg);
  padding: 10px 12px 6px;
}
.scanbar .row { display: flex; gap: 8px; }
.scanbar input {
  flex: 1; min-width: 0;
  padding: 12px 14px;
  font-size: 17px;
  border: 2px solid var(--primary);
  border-radius: 10px;
}
.tabs { display: flex; gap: 6px; overflow-x: auto; padding: 8px 0 2px; }
.tab {
  border: 1px solid var(--line); background: #fff;
  border-radius: 99px; padding: 6px 12px; white-space: nowrap; cursor: pointer; font-size: 14px;
}
.tab.active { background: var(--primary); color: #fff; border-color: var(--primary); }
.tab .n { opacity: .75; margin-left: 4px; }

.item-list { padding: 0 12px 90px; }
.item {
  background: #fff; border: 1px solid var(--line); border-radius: 10px;
  padding: 10px 12px; margin-bottom: 8px;
  display: flex; gap: 10px; align-items: center; cursor: pointer;
}
.item .box { font-weight: 700; color: var(--muted); min-width: 34px; text-align: center; font-size: 13px; }
.item .body { flex: 1; min-width: 0; }
.item .name { font-weight: 600; overflow: hidden; text-overflow: ellipsis; }
.item .meta { font-size: 12px; color: var(--muted); }
.item .cnt { text-align: right; font-size: 14px; white-space: nowrap; }
.item.pending { border-style: dashed; }
.cat-head { font-size: 13px; color: var(--muted); margin: 12px 2px 6px; font-weight: 600; }

.qty-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; margin-top: 12px; }
.qty label { font-size: 13px; color: var(--muted); display: block; margin-bottom: 4px; }
.qty .stepper { display: flex; }
.qty .stepper button { width: 46px; font-size: 22px; border: 1px solid #d1d5db; background: #f9fafb; cursor: pointer; }
.qty .stepper button:first-child { border-radius: 10px 0 0 10px; }
.qty .stepper button:last-child { border-radius: 0 10px 10px 0; }
.qty .stepper input {
  width: 100%; min-width: 0; text-align: center; font-size: 22px; font-weight: 700;
  border: 1px solid #d1d5db; border-left: 0; border-right: 0; padding: 8px 0;
}
.total-line { margin-top: 12px; padding: 10px 12px; background: #f3f4f6; border-radius: 8px; font-size: 16px; }
.round-tag { display: inline-block; margin-left: 6px; }

.inapp-bar { display: block; padding: 10px 12px; background: #fef3c7; color: #92400e; font-size: 14px; text-align: center; text-decoration: underline; }
.netbar { font-size: 12px; padding: 4px 12px; text-align: center; }
.netbar.offline { background: var(--warn-bg); color: var(--warn); }

#camera-box { position: relative; background: #000; border-radius: 10px; overflow: hidden; margin-top: 8px; }
#camera-box video { width: 100%; display: block; max-height: 45vh; object-fit: cover; }
#camera-box .aim { position: absolute; left: 10%; right: 10%; top: 40%; height: 20%; border: 2px solid #22c55e; border-radius: 8px; }

#camera-box video { transform-origin: center; transition: transform .15s; }
#btn-camera.on { background: #dcfce7; border-color: var(--ok); }
.cam-tools { position: absolute; left: 8px; right: 8px; bottom: 8px; display: flex; gap: 6px; align-items: center; }
.cam-zoom { display: flex; gap: 4px; margin-right: auto; }
.cam-tools button {
  min-width: 42px; height: 36px; padding: 0 10px; border-radius: 99px; cursor: pointer; font-size: 14px;
  background: rgba(0,0,0,.55); color: #fff; border: 1px solid rgba(255,255,255,.45);
}
.cam-tools button.on { background: #22c55e; border-color: #22c55e; }

.modebar { display: flex; gap: 6px; align-items: center; flex-wrap: wrap; margin-top: 8px; }
.seg { display: inline-flex; border: 1px solid var(--primary); border-radius: 99px; overflow: hidden; }
.seg button { border: 0; background: #fff; color: var(--primary); padding: 6px 12px; font-size: 14px; cursor: pointer; }
.seg button.on { background: var(--primary); color: #fff; }
.chip { border: 1px solid var(--line); background: #fff; border-radius: 99px; padding: 6px 10px; font-size: 14px; cursor: pointer; }
.chip.on { background: #dcfce7; border-color: var(--ok); color: #166534; }
.scanbar.flash-ok { animation: flash-ok .45s; }
.scanbar.flash-bad { animation: flash-bad .6s; }
@keyframes flash-ok { from { background: #bbf7d0; box-shadow: inset 0 0 0 4px #22c55e; } }
@keyframes flash-bad { from { background: #fecaca; box-shadow: inset 0 0 0 4px #ef4444; } }

.recent { padding: 2px 12px 4px; }
.rc {
  display: flex; gap: 8px; align-items: center; margin-bottom: 6px; padding: 6px 10px;
  background: #fff; border: 1px solid var(--line); border-radius: 10px;
}
.rc.last { border-color: var(--ok); background: #f0fdf4; }
.rc.undone { opacity: .5; }
.rc .body { flex: 1; min-width: 0; }
.rc .name { font-weight: 600; font-size: 14px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.rc .meta { font-size: 12px; color: var(--muted); }
.help-list { margin: 10px 0 0 18px; padding: 0; }
.help-list li { margin-bottom: 8px; font-size: 14px; }

/* ผูกบาร์โค้ดหน้างาน */
.link-box{border:1px dashed #9db7d3;border-radius:10px;padding:10px;margin:6px 0 4px;background:#f5f9fd}
.link-box label{display:block;font-size:13px;font-weight:600;margin-bottom:6px}
.link-box input{width:100%}
#mx-link-list{max-height:240px;overflow-y:auto;margin-top:6px}
#mx-link-list .item{cursor:default}
.link-units{display:flex;flex-wrap:wrap;gap:6px;margin-top:6px}

/* ผู้จัดการแก้ยอด */
td.editable{cursor:pointer}
td.editable:hover{background:#eef4fb}
td.editable .edit-ico{font-size:11px;color:#8aa3bd}
.edit-row{border-top:1px solid #e3e8ef;padding:8px 0}
