:root {
  /* Bakesome: orange #f8af3c for the brand bar and highlights, the logo's charcoal for text and the main action */
  --bg: #f5f3ef;
  --card: #ffffff;
  --ink: #2e2b28;
  --muted: #776f66;
  --line: #e6e0d7;
  --brand: #2e2b28;
  --accent: #f8af3c;
  --accent-ink: #2e2b28;
  --accent-soft: #fff4e2;
  --accent-deep: #b86f00;
  --ok: #2f7d4f;
  --ok-bg: #e4f2e8;
  --warn: #b26b00;
  --warn-bg: #fff1d6;
  --bad: #b3261e;
  --bad-bg: #fbe3e1;
  --radius: 14px;
  --safe-b: env(safe-area-inset-bottom, 0px);
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; background: var(--bg); color: var(--ink); }
* { -webkit-tap-highlight-color: transparent; }
body { font-family: 'IBM Plex Sans Thai', system-ui, sans-serif; font-size: 16px; line-height: 1.5; min-height: 100vh; }
.qty, .tile-count, .pin-dots, .kv, .badge { font-variant-numeric: tabular-nums; }
:focus-visible { outline: 3px solid var(--accent); outline-offset: 2px; }
button, input, select, textarea { font: inherit; color: inherit; }
svg { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; flex: none; }

/* top bar */
#topbar {
  position: sticky; top: 0; z-index: 10; display: flex; align-items: center; gap: 6px;
  padding: calc(env(safe-area-inset-top, 0px) + 10px) 10px 10px; background: var(--accent); color: var(--ink);
  box-shadow: 0 1px 0 rgba(0,0,0,.06);
}
.brand-logo { width: 36px; height: 36px; border-radius: 50%; background: #fff; flex: none; object-fit: contain; padding: 2px; margin-left: 2px; }
.brand { flex: 1; min-width: 0; padding-left: 6px; }
.brand-title { font-weight: 700; font-size: 18px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.brand-sub { font-size: 13px; opacity: .8; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.icon-btn { background: transparent; border: 0; color: inherit; width: 42px; height: 42px; border-radius: 10px; display: grid; place-items: center; cursor: pointer; }
.icon-btn:active { background: rgba(0,0,0,.08); }

main { max-width: 720px; margin: 0 auto; padding: 16px 16px calc(120px + var(--safe-b)); }
h2 { font-size: 20px; margin: 4px 0 12px; }
h3 { font-size: 15px; margin: 22px 0 8px; color: var(--muted); font-weight: 600; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.center { text-align: center; }
.row { display: flex; align-items: center; gap: 8px; }
.row.between { justify-content: space-between; }
.grow { flex: 1; min-width: 0; }
.stack > * + * { margin-top: 10px; }

/* buttons */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  min-height: 48px; padding: 10px 18px; border-radius: 12px; border: 0; cursor: pointer;
  font-weight: 600; background: var(--brand); color: #fff;
}
.btn:active:not(:disabled) { transform: translateY(1px); }
.btn.accent { background: var(--accent); color: var(--accent-ink); }
.btn:disabled { opacity: .45; cursor: not-allowed; }
.btn.dark { background: var(--brand); color: #fff; }
.btn.ghost { background: var(--card); border: 1.5px solid var(--line); color: var(--ink); }
.btn.danger { background: var(--bad-bg); color: var(--bad); }
.btn.small { min-height: 36px; padding: 6px 12px; font-size: 14px; border-radius: 10px; }
.btn.block { width: 100%; }
.link { background: none; border: 0; color: var(--accent-deep); font-weight: 600; cursor: pointer; padding: 6px 4px; }

/* cards */
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px; }
.card + .card { margin-top: 10px; }
.card.tap { cursor: pointer; }
.card.tap:active { background: var(--accent-soft); }
.card.selected { border-color: var(--accent); box-shadow: 0 0 0 2px var(--accent) inset; }
.title { font-weight: 600; line-height: 1.35; }
.qty { font-weight: 700; font-size: 22px; white-space: nowrap; letter-spacing: -.01em; }
.qty small { font-size: 13px; font-weight: 500; color: var(--muted); }

/* home tiles */
.hello { margin: 2px 0 18px; }
.hello b { font-size: 24px; display: block; line-height: 1.25; }
.tiles { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.tile {
  position: relative; background: var(--card); border: 1px solid var(--line); border-radius: 16px; padding: 16px 14px 14px; min-height: 120px;
  display: flex; flex-direction: column; justify-content: space-between; text-align: left; cursor: pointer;
}
.tile:active { background: var(--accent-soft); }
.tile .ic { width: 44px; height: 44px; border-radius: 12px; display: grid; place-items: center; background: var(--accent-soft); color: var(--accent-deep); }
.tile .ic svg { width: 24px; height: 24px; }
.tile { justify-content: flex-start; }
.tile > div:last-of-type { margin-top: 12px; }
/* every tile: one line of title, two lines of description, so all titles and descriptions line up */
.tile b { font-size: 16px; display: block; line-height: 1.35; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.tile .sub { font-size: 13px; color: var(--muted); line-height: 1.4; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical;
  overflow: hidden; min-height: 2.8em; margin-top: 2px; }
/* work waiting on this tile: the one loud thing on the home screen */
.tile.has-work { border-color: var(--accent); box-shadow: inset 0 0 0 1px var(--accent); }
.tile-count { position: absolute; top: 14px; right: 14px; min-width: 34px; height: 34px; padding: 0 9px; border-radius: 17px;
  background: var(--brand); color: #fff; font-weight: 700; font-size: 16px; display: grid; place-items: center; }
.tile .work { color: var(--ink); font-weight: 600; }
.tile .tile-count { color: #fff; font-size: 16px; }

/* scan bar */
.scanbar { display: flex; gap: 8px; margin-bottom: 14px; }
.scanbar input, .field input, .field textarea, .field select, .search {
  width: 100%; min-height: 50px; border: 1.5px solid var(--line); border-radius: 12px; padding: 10px 14px; background: #fff;
}
.scanbar input:focus, .field input:focus, .field textarea:focus, .search:focus { outline: none; border-color: var(--accent); }
.scanbar .cam { width: 54px; flex: none; border: 0; border-radius: 12px; background: var(--accent); color: var(--accent-ink); display: grid; place-items: center; cursor: pointer; }
.scanbar .go { flex: none; width: 54px; padding: 0; }

.field { margin-bottom: 12px; }
.field label { display: block; font-size: 14px; font-weight: 600; margin-bottom: 6px; }
.field .hint { font-size: 12px; color: var(--muted); margin-top: 4px; }
.field-row { display: flex; gap: 8px; }

/* badges & chips */
.badge { display: inline-block; font-size: 12px; font-weight: 600; padding: 2px 8px; border-radius: 999px; background: #eee6da; color: var(--muted); white-space: nowrap; }
.badge.ok { background: var(--ok-bg); color: var(--ok); }
.badge.warn { background: var(--warn-bg); color: var(--warn); }
.badge.bad { background: var(--bad-bg); color: var(--bad); }
.badge.accent { background: var(--accent); color: var(--accent-ink); }
.chip { display: flex; align-items: center; gap: 8px; background: var(--card); border: 1.5px solid var(--line); border-radius: 12px; padding: 10px 12px; }
.loc { display: inline-flex; align-items: center; gap: 4px; font-size: 14px; }
.loc svg { width: 16px; height: 16px; color: var(--muted); }

.kv { display: flex; flex-wrap: wrap; gap: 4px 12px; font-size: 14px; color: var(--muted); margin-top: 4px; }
.lines { margin-top: 10px; border-top: 1px dashed var(--line); padding-top: 8px; }
.line { display: flex; align-items: center; gap: 8px; font-size: 14px; padding: 6px 0; }
.line + .line { border-top: 1px solid #f1eadf; }
.x { border: 0; background: var(--bad-bg); color: var(--bad); width: 32px; height: 32px; border-radius: 8px; display: grid; place-items: center; cursor: pointer; flex: none; }
.x svg { width: 16px; height: 16px; }
.progress { height: 6px; border-radius: 6px; background: #efe6d9; overflow: hidden; margin-top: 8px; }
.progress > i { display: block; height: 100%; background: var(--ok); }
.progress.over > i { background: var(--warn); }

.empty { text-align: center; color: var(--muted); padding: 36px 12px; }
.empty svg { width: 40px; height: 40px; margin-bottom: 6px; opacity: .6; }

/* bottom action bar */
.actionbar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 9; background: var(--card); border-top: 1px solid var(--line);
  padding: 12px 16px calc(12px + var(--safe-b));
}
.actionbar .inner { max-width: 720px; margin: 0 auto; }
.check, .field label.check { display: flex; font-weight: 400; gap: 10px; align-items: flex-start; font-size: 14px; margin-bottom: 10px; }
.check input, .field .check input { width: 20px; height: 20px; min-height: 0; padding: 0; margin: 2px 0 0; flex: none; accent-color: var(--brand); }

/* login */
/* the sign-in screens are locked to the phone's screen: no page scroll, no bounce, no zoom */
html:has(.login), body:has(.login) { height: 100%; overflow: hidden; overscroll-behavior: none; }
body:has(.login) { position: fixed; inset: 0; min-height: 0; }
.login { height: 100vh; height: 100dvh; overflow: hidden; display: flex; flex-direction: column; box-sizing: border-box;
  padding: max(clamp(20px, 6dvh, 48px), env(safe-area-inset-top)) 20px max(16px, env(safe-area-inset-bottom)); max-width: 480px; margin: 0 auto;
  touch-action: manipulation; }
.login .logo { width: clamp(64px, 13dvh, 112px); height: clamp(64px, 13dvh, 112px); margin: 0 0 clamp(8px, 2dvh, 16px); flex: none;
  display: block; border-radius: 50%; background: #fff; box-shadow: 0 2px 10px rgba(0,0,0,.08); }
.login > * { flex: none; }
.login .pick { flex: 0 1 auto; min-height: 0; overflow-y: auto; overscroll-behavior: contain; -webkit-overflow-scrolling: touch; padding-bottom: 2px; }
.login .search { font-size: 16px; }          /* 16px+ so iPhone doesn't zoom in on tap */
.login .pin-dots { margin: clamp(12px, 3dvh, 26px) 0; }
.login .keypad button { min-height: clamp(48px, 8dvh, 62px); }
.login h1 { font-size: 26px; margin: 0 0 4px; }
.pick { display: grid; gap: 10px; margin-top: 20px; }
.pick .btn { justify-content: flex-start; min-height: 58px; font-size: 17px; background: var(--card); color: var(--ink); border: 1px solid var(--line); }
.pick .btn:active { background: var(--accent-soft); border-color: var(--accent); }
.pin-dots { display: flex; justify-content: center; gap: 14px; margin: 26px 0; }
.pin-dots i { width: 16px; height: 16px; border-radius: 50%; border: 2px solid var(--brand); }
.pin-dots i.on { background: var(--brand); }
.keypad { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; }
.keypad button { min-height: 62px; font-size: 24px; font-weight: 600; border-radius: 14px; border: 1px solid var(--line); background: var(--card); cursor: pointer; }
.keypad button:active { background: #efe6d9; }
.keypad .fn { font-size: 15px; background: transparent; border-color: transparent; }

/* modal / bottom sheet */
.overlay { position: fixed; inset: 0; z-index: 20; background: rgba(30,20,12,.5); display: flex; align-items: flex-end; justify-content: center; animation: fade .15s; }
.sheet {
  width: 100%; max-width: 720px; max-height: 92vh; overflow: auto; background: var(--bg);
  border-radius: 20px 20px 0 0; padding: 18px 16px calc(18px + var(--safe-b)); animation: up .18s ease-out;
}
.sheet-title { font-weight: 700; font-size: 18px; margin-bottom: 12px; display: flex; justify-content: space-between; align-items: center; }
#reader { width: 100%; border-radius: 12px; overflow: hidden; background: #000; margin-bottom: 12px; min-height: 240px; }
#reader video { width: 100% !important; }
@keyframes up { from { transform: translateY(40px); opacity: .5; } }
@keyframes fade { from { opacity: 0; } }

/* toast */
#toast {
  position: fixed; left: 50%; bottom: calc(100px + var(--safe-b)); transform: translateX(-50%) translateY(20px);
  background: var(--brand); color: #fff; padding: 12px 18px; border-radius: 12px; z-index: 40; max-width: calc(100% - 32px);
  opacity: 0; pointer-events: none; transition: .2s; font-size: 15px; box-shadow: 0 6px 20px rgba(0,0,0,.2);
}
#toast.show { opacity: 1; transform: translateX(-50%); }
body:has(.actionbar) #toast { bottom: calc(150px + var(--safe-b)); }   /* stay above the bottom buttons */
#toast.error { background: var(--bad); }
#toast.ok { background: var(--ok); }

.spinner { width: 28px; height: 28px; border: 3px solid var(--line); border-top-color: var(--brand); border-radius: 50%; animation: spin .8s linear infinite; margin: 30px auto; }
@keyframes spin { to { transform: rotate(360deg); } }
.done-ic { width: 72px; height: 72px; border-radius: 50%; background: var(--ok-bg); color: var(--ok); display: grid; place-items: center; margin: 24px auto 12px; }
.done-ic svg { width: 40px; height: 40px; stroke-width: 2.5; }

/* product thumbnails & photo viewer */
.thumb {
  position: relative; width: 52px; height: 52px; flex: none; padding: 0; border: 1px solid var(--line);
  border-radius: 10px; overflow: hidden; background: #f1e9de; color: #bfae9c; display: grid; place-items: center; cursor: zoom-in;
}
.thumb svg { width: 22px; height: 22px; }
.thumb img { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; background: #fff; }
.thumb.sm { width: 40px; height: 40px; border-radius: 8px; }
.thumb.lg { width: 72px; height: 72px; border-radius: 12px; border-color: rgba(255,255,255,.2); }
.lightbox { position: fixed; inset: 0; z-index: 50; background: rgba(15,10,6,.94); animation: fade .15s; }
.lb-scroll { position: absolute; inset: 0; overflow: auto; display: flex; padding: 56px 12px 48px; -webkit-overflow-scrolling: touch; }
.lb-scroll img { margin: auto; max-width: 100%; max-height: 100%; object-fit: contain; border-radius: 8px; background: #fff; cursor: zoom-in; }
.lightbox.zoomed .lb-scroll img { max-width: none; max-height: none; width: 250%; cursor: zoom-out; }
.lb-close { position: absolute; top: calc(env(safe-area-inset-top, 0px) + 8px); right: 8px; z-index: 2; color: #fff; background: rgba(255,255,255,.12); }
.lb-hint { position: absolute; left: 0; right: 0; bottom: calc(14px + var(--safe-b)); text-align: center; color: rgba(255,255,255,.6); font-size: 13px; pointer-events: none; }
.lightbox .empty { color: rgba(255,255,255,.7); margin: auto; }

/* photos */
.photobox + .photobox { margin-top: 12px; padding-top: 12px; border-top: 1px dashed var(--line); }
.ph-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(76px, 1fr)); gap: 8px; margin-top: 8px; }
.ph { position: relative; aspect-ratio: 1; border-radius: 10px; overflow: hidden; background: #efe6d9; }
.ph img { width: 100%; height: 100%; object-fit: cover; cursor: zoom-in; display: block; }
.ph .x { position: absolute; top: 4px; right: 4px; width: 26px; height: 26px; border-radius: 50%; background: rgba(0,0,0,.55); color: #fff; }
.ph .x svg { width: 14px; height: 14px; }
.ph.add { display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px; cursor: pointer;
  border: 1.5px dashed #d9cbb8; background: var(--card); color: var(--accent-deep); font-size: 12px; font-weight: 600; }
.ph.add svg { width: 24px; height: 24px; }

/* type-ahead suggestions */
.suggest { margin: -8px 0 14px; background: var(--card); border: 1px solid var(--line); border-radius: 14px; overflow: hidden;
  box-shadow: 0 10px 28px rgba(40,25,10,.14); position: relative; z-index: 5; }
.suggest .sg { display: flex; align-items: center; gap: 12px; padding: 10px 12px; cursor: pointer; min-height: 60px; }
.suggest .sg + .sg { border-top: 1px solid #f1eadf; }
.suggest .sg:active, .suggest .sg:hover { background: #f6efe4; }
.suggest .thumb { cursor: pointer; pointer-events: none; }
.suggest .sg-text { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 2px; }
.suggest .sg-name { font-weight: 600; line-height: 1.3; overflow: hidden; text-overflow: ellipsis; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; }
.suggest .sg-name b { font-weight: 800; color: var(--warn); }
.suggest .sg-meta { font-size: 13px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.suggest .sg-meta b { font-weight: 600; }
.sg-have { color: var(--ok); }
.sg-none { color: var(--bad); }
.sg-in { color: var(--accent-deep); }
.suggest .sg-go { width: 18px; height: 18px; color: #c9b9a6; flex: none; }

/* ---- activity feedback ---- */
/* thin moving bar under the header while waiting for Be1 */
#topbar { position: sticky; }
#topbar::after { content: ""; position: absolute; left: 0; right: 0; bottom: 0; height: 3px; opacity: 0; transition: opacity .2s;
  background: linear-gradient(90deg, transparent 0, #333 35%, #666 50%, #333 65%, transparent 100%);
  background-size: 50% 100%; background-repeat: no-repeat; }
body.loading #topbar::after { opacity: 1; animation: slide 1s ease-in-out infinite; }
@keyframes slide { from { background-position: -50% 0; } to { background-position: 150% 0; } }

/* search button turns into a spinner while the search runs */
.scanbar.busy .go svg { display: none; }
.scanbar.busy .go::after { content: ""; width: 20px; height: 20px; border: 2.5px solid rgba(42,28,18,.25); border-top-color: var(--accent-ink);
  border-radius: 50%; animation: spin .7s linear infinite; }
.scanbar.busy input { background: linear-gradient(90deg, #fff 0%, #fbf3e6 50%, #fff 100%); background-size: 200% 100%; animation: shimmer 1.1s linear infinite; }
@keyframes shimmer { from { background-position: 100% 0; } to { background-position: -100% 0; } }

/* "กำลังค้นหา…" under the box while typing */
.sg-wait { display: flex; align-items: center; gap: 10px; padding: 14px 16px; color: var(--muted); font-size: 14px; }
.dots { display: inline-flex; gap: 4px; }
.dots i { width: 7px; height: 7px; border-radius: 50%; background: var(--accent); animation: bounce 1s infinite ease-in-out; }
.dots i:nth-child(2) { animation-delay: .15s; } .dots i:nth-child(3) { animation-delay: .3s; }
@keyframes bounce { 0%, 80%, 100% { transform: scale(.5); opacity: .4; } 40% { transform: scale(1); opacity: 1; } }

.loading-block { text-align: center; padding: 26px 0; }
.loading-block .spinner { margin: 0 auto 10px; }

/* buttons that are working */
.btn:disabled[data-label] { position: relative; }
@media (prefers-reduced-motion: reduce) { *, *::after { animation-duration: 0s !important; } }

/* pick list: where from -> where to */
.route { background: var(--brand); color: #fff; border-radius: var(--radius); padding: 12px 14px; margin-bottom: 14px; }
.route .muted { color: rgba(255,255,255,.7); display: block; }
.route .link { color: var(--accent); }
.route-row { display: flex; align-items: center; gap: 10px; }
.route-tag { flex: none; background: var(--accent); color: var(--accent-ink); font-weight: 700; font-size: 13px; padding: 4px 10px; border-radius: 999px; }
.route-loc { display: block; font-size: 17px; word-break: break-word; }
.route-sum { margin-top: 8px; padding-top: 8px; border-top: 1px solid rgba(255,255,255,.15); font-size: 14px; color: rgba(255,255,255,.85); }
.pick-group { border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; background: var(--card); margin-bottom: 12px; }
.pick-head { display: flex; align-items: center; gap: 10px; padding: 10px 12px; background: var(--brand); color: #fff; }
.pick-head .badge.warn { background: var(--warn-bg); }
.pick-no { flex: none; width: 28px; height: 28px; border-radius: 50%; background: var(--accent); color: var(--accent-ink); font-weight: 800; display: grid; place-items: center; }
.pick-line { display: flex; align-items: center; gap: 10px; padding: 12px; cursor: pointer; }
.pick-line + .pick-line { border-top: 1px solid #f1eadf; }
.pick-line:active { background: #f6efe4; }
.pick-line .kv { align-items: center; }

[hidden] { display: none !important; }

/* history → document detail */
.more-hint { text-align: right; font-size: 13px; color: var(--accent-deep); margin-top: 6px; font-weight: 600; }
.doc-grid { display: grid; grid-template-columns: auto 1fr; gap: 6px 12px; margin-top: 10px; font-size: 14px; }
.log-item { padding: 8px 0; border-top: 1px solid var(--line); }
.log-item:first-child { border-top: 0; padding-top: 0; }
.log-item.app { border-left: 3px solid var(--accent); padding-left: 10px; }

/* between branches: tabs */
.tabs { display: flex; gap: 4px; background: var(--line); padding: 4px; border-radius: 12px; margin-bottom: 14px; }
.tab { flex: 1; border: 0; background: transparent; font: inherit; font-weight: 600; font-size: 14px; color: var(--muted);
  padding: 10px 4px; border-radius: 9px; cursor: pointer; display: flex; align-items: center; justify-content: center; gap: 6px; }
.tab.on { background: var(--card); color: var(--ink); box-shadow: 0 1px 3px rgba(0,0,0,.08); }
.tab .cnt { background: var(--bad); color: #fff; font-size: 12px; min-width: 20px; height: 20px; border-radius: 10px;
  display: inline-flex; align-items: center; justify-content: center; padding: 0 6px; }
.danger-text { color: var(--bad) !important; border-color: var(--bad-bg) !important; }

/* putaway waiting list */
.putaway-banner { display: flex; align-items: center; gap: 12px; width: 100%; text-align: left; font: inherit; color: inherit;
  border: 1.5px solid var(--accent); background: var(--accent-soft); margin-bottom: 14px; cursor: pointer; }
.putaway-banner .grow { display: flex; flex-direction: column; gap: 2px; }
.putaway-banner .pb-ic { width: 40px; height: 40px; border-radius: 12px; background: var(--accent); display: grid; place-items: center; flex: none; }
.putaway-banner .pb-ic svg { width: 22px; height: 22px; }
.putaway-next { border: 1.5px solid var(--accent); background: var(--accent-soft); }
.card.pend { cursor: pointer; }
.card.selected { border-color: var(--accent); box-shadow: 0 0 0 2px var(--accent-soft); }

/* photo search */
.ph-shot { display: block; width: 100%; max-height: 220px; object-fit: contain; border-radius: 12px; background: #000; margin-bottom: 12px; }
.ph-shot.small { width: 64px; height: 64px; max-height: none; object-fit: cover; margin: 0; flex: none; }
.card.best { border-color: var(--accent); box-shadow: inset 0 0 0 1px var(--accent); }

/* product barcode */
.bc-card { display: block; width: 100%; background: #fff; padding: 10px; cursor: pointer; text-align: center; }
svg.bc { stroke: none; fill: #111; flex: initial; }
.bc-card .bc { display: block; width: 100%; max-width: 320px; height: auto; margin: 0 auto; }
.bc-big { background: #fff; border-radius: 12px; padding: 16px 4px; }
.bc-big .bc { display: block; width: 100%; height: auto; }
