/* Kat Leong Ops — designed for one-handed use on a phone in a busy fresh mart:
   big targets (≥ 56px), high contrast, colour + word for every status. */
:root {
  --brand: #7a1f1f;
  --brand-dark: #5c1515;
  --brand-soft: #f6eaea;
  --brand-ink: #fff;
  --accent: #e9a23b;
  --bg: #f5f3ef;
  --card: #ffffff;
  --ink: #1f1b18;
  --muted: #6b645c;
  --line: #e4ded5;
  --short: #c62828;
  --short-bg: #fdecea;
  --over: #a15c00;
  --over-bg: #fff3df;
  --ok: #1d7a3e;
  --ok-bg: #e6f4ea;
  --pending: #55606e;
  --pending-bg: #eceff3;
  --radius: 14px;
  --tap: 56px;
  --shadow: 0 1px 2px rgba(31,27,24,.05), 0 4px 14px rgba(31,27,24,.05);
  --ring: 0 0 0 4px rgba(122,31,31,.16);
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, "Noto Sans", "PingFang SC", "Microsoft YaHei", "Noto Sans SC",
    "Noto Sans Myanmar", "Myanmar Text", "Myanmar Sangam MN", Padauk, sans-serif;
  color: var(--ink);
  background: var(--bg);
  -webkit-tap-highlight-color: transparent;
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
}
* { box-sizing: border-box; }
/* App-like on phones: no pinch or double-tap zoom, no rubber-band scroll of the whole page.
   (Inputs stay ≥ 16px so iPhone does not zoom in when a field is tapped.) */
html { touch-action: pan-x pan-y; overscroll-behavior-y: none; }
html, body { margin: 0; min-height: 100%; background: var(--bg); }
body { font-size: 17px; line-height: 1.45; padding-bottom: env(safe-area-inset-bottom); -webkit-font-smoothing: antialiased; }
/* Myanmar script has tall stacked marks; give the lines room so they are not clipped. */
:lang(my) body, body:lang(my) { line-height: 1.75; }
:lang(my) .btn, :lang(my) .chip, :lang(my) .badge, :lang(my) .tile, :lang(my) .langseg button { line-height: 1.7; }
button, input, select, textarea { font: inherit; color: inherit; }
button { touch-action: manipulation; }
h1, h2, h3 { margin: 0; line-height: 1.25; letter-spacing: -.01em; }
h1 { font-size: 22px; } h2 { font-size: 19px; } h3 { font-size: 17px; }
:lang(my) h1, :lang(my) h2, :lang(my) h3 { line-height: 1.7; letter-spacing: 0; }
h3.sect, .sect { font-size: 13px; font-weight: 700; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); }
:lang(zh) .sect, :lang(my) .sect { letter-spacing: 0; font-size: 14px; }
p { margin: 0; }
.muted { color: var(--muted); }
.small { font-size: 14px; }
.mono { font-family: ui-monospace, "SF Mono", Menlo, Consolas, monospace; }
.num { font-variant-numeric: tabular-nums; }
.hidden { display: none !important; }
.icon { flex: none; display: block; }
:focus-visible { outline: 3px solid rgba(122,31,31,.45); outline-offset: 2px; }

/* ---------- layout ---------- */
.topbar {
  position: sticky; top: 0; z-index: 10;
  display: flex; align-items: center; gap: 6px;
  min-height: 58px; padding: calc(env(safe-area-inset-top) + 7px) 10px 7px;
  background: linear-gradient(180deg, var(--brand) 0%, var(--brand-dark) 100%); color: var(--brand-ink);
  box-shadow: 0 1px 0 rgba(0,0,0,.12), 0 6px 16px rgba(92,21,21,.18);
}
.topbar .title { flex: 1; min-width: 0; padding: 0 4px; }
.topbar .title b { display: block; font-size: 17px; font-weight: 650; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.topbar .title span { display: block; font-size: 13px; opacity: .82; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.topbar button { background: transparent; border: 0; color: inherit; min-width: 44px; min-height: 44px; border-radius: 12px; font-size: 15px; cursor: pointer; }
.topbar .iconbtn { display: inline-flex; align-items: center; justify-content: center; width: 44px; padding: 0; background: rgba(255,255,255,.1); }
.topbar button:hover { background: rgba(255,255,255,.16); }
.topbar button:active { background: rgba(255,255,255,.24); }
.topbar :focus-visible { outline-color: #fff; }
.net { font-size: 12px; font-weight: 600; padding: 4px 10px; border-radius: 99px; background: rgba(255,255,255,.16); white-space: nowrap; }
.net.off { background: var(--accent); color: #2b1a00; }

main { padding: 16px; max-width: 720px; margin: 0 auto; }
main.wide { max-width: 1200px; }
.stack > * + * { margin-top: 12px; }
.row { display: flex; gap: 10px; align-items: center; }
.row > .grow { flex: 1; min-width: 0; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }

.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; box-shadow: var(--shadow); }
.card.tight { padding: 12px 14px; }
.card .card { box-shadow: none; }
details > summary { cursor: pointer; font-weight: 600; min-height: 40px; display: flex; align-items: center; color: var(--brand); }

/* ---------- buttons ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  min-height: var(--tap); padding: 0 20px; border-radius: var(--radius);
  border: 1.5px solid var(--line); background: var(--card); color: var(--ink);
  font-weight: 600; font-size: 17px; cursor: pointer; box-shadow: 0 1px 2px rgba(31,27,24,.05);
  text-decoration: none; user-select: none; -webkit-user-select: none;
  transition: background .15s, border-color .15s, box-shadow .15s, transform .05s;
}
.btn:hover { border-color: #cfc7bb; }
.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: .45; cursor: not-allowed; }
.btn.block { width: 100%; }
.btn.primary { background: var(--brand); border-color: var(--brand); color: var(--brand-ink); box-shadow: 0 2px 8px rgba(122,31,31,.25); }
.btn.primary:hover { background: var(--brand-dark); border-color: var(--brand-dark); }
.btn.go { background: var(--ok); border-color: var(--ok); color: #fff; box-shadow: 0 2px 8px rgba(29,122,62,.25); }
.btn.danger { background: var(--card); color: var(--short); border-color: var(--short); box-shadow: none; }
.btn.ghost { background: transparent; box-shadow: none; }
.btn.ghost:hover { background: rgba(31,27,24,.04); }
.btn.xl { min-height: 64px; font-size: 19px; }
.btn.small { min-height: 40px; font-size: 15px; padding: 0 14px; border-radius: 10px; }

.tile {
  display: flex; align-items: center; gap: 14px;
  min-height: 84px; padding: 14px 16px; border-radius: var(--radius); border: 1px solid var(--line); text-align: left;
  background: var(--card); box-shadow: var(--shadow); cursor: pointer; font-weight: 650; font-size: 17px; width: 100%;
  transition: border-color .15s, box-shadow .15s, transform .05s;
}
.tile:hover { border-color: #cfc7bb; box-shadow: 0 2px 4px rgba(31,27,24,.06), 0 8px 22px rgba(31,27,24,.08); }
.tile:active { transform: translateY(1px); }
.tile .grow { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 2px; }
.tile .ico {
  flex: none; display: inline-flex; align-items: center; justify-content: center; min-width: 48px; height: 48px; padding: 0 10px;
  border-radius: 12px; background: var(--brand-soft); color: var(--brand); font-size: 14px; font-weight: 800; letter-spacing: .02em; line-height: 1;
}
.tile small { font-weight: 400; font-size: 13px; color: var(--muted); }
.tile > .icon { color: #b9b0a4; }
.tile.main { background: linear-gradient(135deg, var(--brand) 0%, var(--brand-dark) 100%); border-color: var(--brand-dark); color: #fff;
  min-height: 104px; font-size: 20px; box-shadow: 0 6px 20px rgba(122,31,31,.28); }
.tile.main .ico { background: rgba(255,255,255,.16); color: #fff; min-width: 60px; height: 60px; border-radius: 16px; }
.tile.main small { color: rgba(255,255,255,.85); font-size: 14px; }
.tile:disabled { opacity: .55; cursor: default; }
.tiles > .tile.main { grid-column: 1 / -1; }
@media (max-width: 520px) { .tiles { grid-template-columns: 1fr; } }

/* ---------- login ---------- */
.login { min-height: 100vh; min-height: 100dvh; }
.login-hero {
  padding: calc(env(safe-area-inset-top) + 44px) 20px 76px; text-align: center; color: #fff;
  background: linear-gradient(160deg, #8c2626 0%, var(--brand) 45%, var(--brand-dark) 100%);
  border-radius: 0 0 28px 28px;
}
.login-hero img { border-radius: 20px; box-shadow: 0 8px 24px rgba(0,0,0,.25); background: #fff; }
.login-hero h1 { margin-top: 14px; font-size: 24px; }
.login-hero .sub { opacity: .85; font-size: 15px; margin-top: 2px; }
.login main { margin-top: -52px; max-width: 460px; }
.login-card { padding: 20px; box-shadow: 0 10px 34px rgba(31,27,24,.12); }

.langseg { display: grid; grid-template-columns: repeat(3, 1fr); gap: 4px; padding: 4px; border-radius: 14px; background: #e9e4dc; }
.langseg button { min-height: 44px; border: 0; border-radius: 10px; background: transparent; font-weight: 600; font-size: 15px; color: var(--muted); cursor: pointer; }
.langseg button.on { background: var(--card); color: var(--brand); box-shadow: 0 1px 3px rgba(31,27,24,.16); }

/* ---------- forms ---------- */
label.field { display: block; }
label.field > span { display: block; font-size: 14px; font-weight: 600; color: var(--muted); margin-bottom: 6px; }
.input {
  width: 100%; min-height: var(--tap); padding: 0 14px; border-radius: 12px;
  border: 1.5px solid var(--line); background: #fff; font-size: 18px;
  transition: border-color .15s, box-shadow .15s;
}
.input::placeholder { color: #a39b90; }
.input:focus { outline: none; border-color: var(--brand); box-shadow: var(--ring); }
textarea.input { min-height: 88px; padding: 12px 14px; }
select.input { appearance: none; -webkit-appearance: none; padding-right: 38px;
  background-image: linear-gradient(45deg, transparent 50%, var(--muted) 50%), linear-gradient(135deg, var(--muted) 50%, transparent 50%);
  background-position: calc(100% - 20px) 50%, calc(100% - 14px) 50%; background-size: 6px 6px; background-repeat: no-repeat; }
input[type=checkbox] { accent-color: var(--brand); width: 22px; height: 22px; flex: none; }
.error { color: var(--short); font-weight: 600; }
.error:empty { display: none; }

/* ---------- status badges ---------- */
.badge { display: inline-flex; align-items: center; gap: 4px; padding: 3px 10px; border-radius: 99px; font-size: 13px; font-weight: 700; white-space: nowrap; }
.badge.short { background: var(--short-bg); color: var(--short); }
.badge.over { background: var(--over-bg); color: var(--over); }
.badge.match { background: var(--ok-bg); color: var(--ok); }
.badge.pending, .badge.counting { background: var(--pending-bg); color: var(--pending); }
.badge.submitted { background: var(--over-bg); color: var(--over); }
.badge.approved, .badge.synced { background: var(--ok-bg); color: var(--ok); }
.badge.void, .badge.sync_failed { background: var(--short-bg); color: var(--short); }
.badge.not_posted { background: var(--pending-bg); color: var(--pending); }

/* ---------- scan area ---------- */
.scanbox { display: grid; grid-template-columns: 1fr auto; gap: 10px; }
.scanbtn { min-height: 88px; font-size: 21px; border-radius: 18px; }
.scanbtn .ico { font-size: 28px; }

.product { border-left: 6px solid var(--brand); }
.product .name { font-size: 20px; font-weight: 700; }
.kv { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin-top: 10px; }
.kv div { background: var(--bg); border-radius: 10px; padding: 8px 10px; }
.kv div span { display: block; font-size: 12px; color: var(--muted); }
.kv div b { font-size: 18px; }

.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chip { min-height: 44px; padding: 0 16px; border-radius: 99px; border: 1.5px solid var(--line); background: #fff; font-weight: 600; cursor: pointer; white-space: nowrap;
  transition: background .15s, border-color .15s, color .15s; }
.chip.on { border-color: var(--brand); background: var(--brand); color: #fff; }

.qtyshow {
  font-size: 44px; font-weight: 800; text-align: right; padding: 8px 14px; border-radius: 12px;
  background: #fff; border: 2px solid var(--brand); min-height: 72px; font-variant-numeric: tabular-nums; line-height: 1.25;
}
.qtyshow small { font-size: 18px; color: var(--muted); font-weight: 600; margin-left: 6px; }
.keypad { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.keypad button { min-height: 60px; font-size: 26px; font-weight: 700; border-radius: 12px; border: 1px solid var(--line); background: #fff; box-shadow: 0 1px 2px rgba(31,27,24,.05); cursor: pointer;
  user-select: none; -webkit-user-select: none; }
.keypad button:active { background: var(--line); }
.keypad button:disabled { opacity: .35; }
.keypad button.fn { font-size: 17px; background: var(--bg); }

.preview { padding: 10px 12px; border-radius: 10px; font-weight: 600; white-space: normal; }

/* ---------- lists ---------- */
.list { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); overflow: hidden; }
.li { display: flex; gap: 12px; align-items: center; padding: 13px 14px; border-top: 1px solid var(--line); cursor: pointer; transition: background .12s; }
.li:first-child { border-top: 0; }
.li:hover { background: #faf8f5; }
.li:active { background: #f3efe9; }
.li .grow { flex: 1; min-width: 0; }
.li .grow b { display: block; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.li .right { text-align: right; }
.li.queued { background: #fffbe9; }
.li.flag { box-shadow: inset 4px 0 0 var(--accent); }
.list.wrap .li .grow b { white-space: normal; }
.li.off { cursor: default; }
.li.off:hover, .li.off:active { background: none; }
.li.off b { color: var(--muted); font-weight: 600; }
.li .grow b + span { display: block; }

.tabs { display: flex; gap: 6px; overflow-x: auto; flex-wrap: nowrap; scrollbar-width: none; margin-left: -16px; margin-right: -16px; padding: 2px 16px; }
.tabs::-webkit-scrollbar { display: none; }

.summary { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; }
.summary div { background: var(--card); border: 1px solid var(--line); border-radius: 12px; padding: 10px 6px; text-align: center; box-shadow: var(--shadow); }
.summary b { display: block; font-size: 22px; font-variant-numeric: tabular-nums; }
.summary span { font-size: 12px; color: var(--muted); }

.stickyfoot { position: sticky; bottom: 0; padding: 12px 0 calc(12px + env(safe-area-inset-bottom)); background: linear-gradient(transparent, var(--bg) 30%); }
.stickyfoot:empty { display: none; }

/* ---------- tables (desktop) ---------- */
.tablewrap { overflow-x: auto; background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); }
table { border-collapse: collapse; width: 100%; font-size: 15px; }
th, td { padding: 10px 12px; border-bottom: 1px solid var(--line); text-align: left; white-space: nowrap; vertical-align: top; }
tbody tr:last-child td { border-bottom: 0; }
tbody tr:hover td { background: #faf8f5; }
th { font-size: 12px; color: var(--muted); font-weight: 700; text-transform: uppercase; letter-spacing: .04em; background: #faf8f5; position: sticky; top: 0; }
:lang(zh) th, :lang(my) th { letter-spacing: 0; font-size: 13px; }
td.r, th.r { text-align: right; }
tr.short td.v { color: var(--short); font-weight: 700; }
tr.over td.v { color: var(--over); font-weight: 700; }

.kpis { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 12px; }
.kpi { min-width: 0; }
.kpi { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px 16px; box-shadow: var(--shadow); }
.kpi b { display: block; font-size: clamp(20px, 5.6vw, 28px); line-height: 1.25; font-variant-numeric: tabular-nums; white-space: nowrap; }
.kpi span { font-size: 13px; color: var(--muted); }
.kpi.warn { border-top: 3px solid var(--short); }
.kpi.warn b { color: var(--short); }
.bar { height: 10px; border-radius: 6px; background: var(--short); }
.bar.over { background: var(--accent); }

/* ---------- overlays ---------- */
#toast {
  position: fixed; left: 50%; top: calc(68px + env(safe-area-inset-top)); transform: translateX(-50%) translateY(-20px);
  background: var(--ink); color: #fff; padding: 12px 18px; border-radius: 12px; font-weight: 600; max-width: 92vw; text-align: center;
  transition: transform .2s, opacity .2s; opacity: 0; pointer-events: none; z-index: 100; box-shadow: 0 8px 26px rgba(0,0,0,.28);
}
#toast.show { transform: translateX(-50%) translateY(0); opacity: 1; }
#toast.bad { background: var(--short); }
#toast.good { background: var(--ok); }

.modal { position: fixed; inset: 0; z-index: 50; background: rgba(31,27,24,.5); display: flex; align-items: flex-end; justify-content: center; animation: fade .15s ease-out; }
.sheet { background: var(--bg); width: 100%; max-width: 720px; max-height: 92vh; max-height: 92dvh; overflow-y: auto; overscroll-behavior: contain;
  border-radius: 22px 22px 0 0; padding: 10px 16px calc(18px + env(safe-area-inset-bottom)); box-shadow: 0 -8px 40px rgba(0,0,0,.2); animation: rise .2s ease-out; }
.sheet .grab { width: 40px; height: 4px; border-radius: 4px; background: #cfc7bb; margin: 0 auto 14px; }
@media (min-width: 760px) { .modal { align-items: center; } .sheet { border-radius: 22px; padding-top: 18px; } .sheet .grab { display: none; } }
@keyframes fade { from { opacity: 0; } }
@keyframes rise { from { transform: translateY(24px); opacity: 0; } }
@media (prefers-reduced-motion: reduce) { *, *::before, *::after { animation: none !important; transition: none !important; } }

.camera { position: fixed; inset: 0; z-index: 60; background: #000; display: flex; flex-direction: column; }
.camera video { flex: 1; width: 100%; object-fit: cover; }
.camera .frame { position: absolute; left: 10%; right: 10%; top: 35%; height: 22%; border: 3px solid var(--accent); border-radius: 16px; box-shadow: 0 0 0 9999px rgba(0,0,0,.35); pointer-events: none; }
.camera .cbar { position: absolute; left: 0; right: 0; bottom: 0; padding: 16px 16px calc(16px + env(safe-area-inset-bottom)); display: flex; gap: 10px; }
.camera .msg { position: absolute; top: calc(env(safe-area-inset-top) + 16px); left: 16px; right: 16px; color: #fff; text-align: center; font-weight: 600; }

@media (min-width: 900px) {
  body { font-size: 16px; }
  main { padding: 24px; }
  .grid-desktop { display: grid; grid-template-columns: 1fr 1fr; gap: 20px; align-items: start; }
}

/* ---------- printing the variance report ---------- */
@media print {
  html, body { background: #fff; }
  .topbar { position: static; background: none; color: #000; box-shadow: none; border-bottom: 2px solid #000; }
  .topbar button, .actions, .chips, #toast, .modal, .btn, .noprint { display: none !important; }
  main, main.wide { max-width: none; padding: 0; }
  .card, .kpi, .summary div, .tablewrap, .list { box-shadow: none; border-color: #bbb; }
  .tablewrap { overflow: visible; }
  th { position: static; }
  th, td { white-space: normal; }
}

/* Phone: a setting's explanation goes on its own line above its field and Save button. */
@media (max-width: 520px) {
  .row:has(> .input) { flex-wrap: wrap; }
  .row:has(> .input) > .grow { flex-basis: 100%; }
}
