:root{
  --bg:#F4F6FB; --surf:#FFFFFF; --surf2:#EEF1F7; --border:#DDE2EC;
  --t1:#11151F; --t2:#5B6475; --t3:#9AA3B2;
  --accent:#F97316; --green:#16A34A; --loyal:#7C3AED; --amber:#D97706; --red:#DC2626;
  --header-h:56px; --nav-h:64px;
}

*{box-sizing:border-box}
html,body{height:100%}
body{
  margin:0; background:var(--bg); color:var(--t1);
  font-family:system-ui,-apple-system,"Segoe UI",Roboto,sans-serif;
  -webkit-font-smoothing:antialiased; text-rendering:optimizeLegibility;
}

/* ---- fixed header ---- */
.app-header{
  position:fixed; top:0; left:0; right:0; z-index:20;
  height:calc(var(--header-h) + env(safe-area-inset-top));
  padding:env(safe-area-inset-top) 16px 0;
  display:flex; align-items:center; justify-content:space-between;
  background:var(--surf); border-bottom:1px solid var(--border);
}
.brand{font-weight:700; font-size:18px; letter-spacing:.01em}
.install-btn{
  border:0; background:var(--accent); color:#fff; font-weight:600;
  padding:8px 14px; border-radius:10px; font-size:14px; cursor:pointer;
}

/* ---- main scroll area ---- */
.app-main{
  max-width:560px; margin:0 auto; min-height:100%;
  padding:calc(var(--header-h) + env(safe-area-inset-top) + 12px) 16px
          calc(var(--nav-h) + env(safe-area-inset-bottom) + 16px);
}
.view{display:none}
.view.active{display:block}
.view-title{font-size:20px; margin:4px 0 12px}

.card{
  background:var(--surf); border:1px solid var(--border); border-radius:14px;
  padding:16px; margin-bottom:14px;
}
.muted-card{background:var(--surf2); border-style:dashed}
.card-h{
  margin:0 0 8px; font-size:12px; color:var(--t2);
  text-transform:uppercase; letter-spacing:.05em; font-weight:700;
}
.muted{color:var(--t2); font-size:14px; line-height:1.5; margin:0}

.row{display:flex; justify-content:space-between; align-items:center; padding:8px 0; font-size:14px}
.row + .row{border-top:1px solid var(--border)}
.status{font-weight:600}
.status.ok{color:var(--green)}
.status.bad{color:var(--red)}

/* ---- bottom nav ---- */
.bottom-nav{
  position:fixed; left:0; right:0; bottom:0; z-index:20;
  height:calc(var(--nav-h) + env(safe-area-inset-bottom));
  padding-bottom:env(safe-area-inset-bottom);
  display:flex; background:var(--surf); border-top:1px solid var(--border);
}
.nav-btn{
  flex:1; border:0; background:none; color:var(--t2); cursor:pointer;
  display:flex; flex-direction:column; align-items:center; justify-content:center; gap:3px;
  font-size:12px; font-weight:600; padding:6px 0;
}
.nav-ic{font-size:20px; line-height:1; filter:grayscale(1); opacity:.65}
.nav-btn.active{color:var(--accent)}
.nav-btn.active .nav-ic{filter:none; opacity:1}

/* ---- offline banner ---- */
.offline-banner{
  position:fixed; left:0; right:0; z-index:25;
  top:calc(var(--header-h) + env(safe-area-inset-top));
  background:var(--amber); color:#fff; text-align:center;
  font-size:13px; font-weight:600; padding:6px;
}
.offline-banner.syncing{ background:var(--accent); }  /* online with a queue draining */
.is-offline .app-main{
  padding-top:calc(var(--header-h) + env(safe-area-inset-top) + 44px);
}

/* ===== Shop worklist (Step 3) ===== */
.shop-controls{ margin-bottom:12px; }
.ctrl-row{ display:flex; gap:10px; }
.field{ display:flex; flex-direction:column; gap:4px; flex:1; margin-bottom:10px; }
.field-lbl{ font-size:11px; font-weight:700; text-transform:uppercase; letter-spacing:.04em; color:var(--t2); }
.field select,
.field input[type="text"]{
  width:100%; font-size:15px; color:var(--t1); background:var(--surf);
  border:1px solid var(--border); border-radius:10px; padding:10px 12px;
  appearance:none; -webkit-appearance:none;
}
.field select:disabled{ color:var(--t3); background:var(--surf2); }

/* intake row */
.intake-row{
  display:flex; align-items:center; gap:8px; margin-bottom:14px;
  border:1.5px dashed var(--border); border-radius:12px; padding:8px 10px; background:var(--surf2);
}
.intake-row input{
  flex:1; min-width:0; border:0; background:transparent; outline:none;
  font-size:15px; color:var(--t1); padding:6px 2px;
}
.intake-row input::placeholder{ color:var(--t3); }
.icon-btn{
  flex:none; width:38px; height:38px; border:1px solid var(--border); border-radius:9px;
  background:var(--surf); color:var(--t2); font-size:16px; cursor:pointer;
  display:flex; align-items:center; justify-content:center;
}
.icon-btn.add{ background:var(--accent); border-color:var(--accent); color:#fff; font-size:20px; }
.icon-btn.listening{ background:var(--red); border-color:var(--red); color:#fff; animation:mic-pulse 1s infinite; }
@keyframes mic-pulse{ 50%{ opacity:.5; } }

/* worklist */
.worklist{ list-style:none; margin:0; padding:0; }
.wl-empty{
  text-align:center; color:var(--t3); font-size:14px; padding:22px 10px;
  border:1.5px dashed var(--border); border-radius:12px;
}
.wl-row{ position:relative; margin-bottom:8px; border-radius:12px; overflow:hidden; }
.row-bg{
  position:absolute; inset:0; display:flex; align-items:center; padding:0 18px;
  font-weight:700; font-size:14px; color:#fff; opacity:0;
}
.wl-row.revealing .row-bg{ opacity:1; }
.row-bg.right{ justify-content:flex-start; background:var(--green); }  /* to-buy -> basket */
.row-bg.left{ justify-content:flex-end;   background:var(--t2); }     /* basket -> back   */
.row-fg{
  position:relative; display:flex; align-items:center; gap:8px;
  background:var(--surf); border:1px solid var(--border); border-radius:12px;
  padding:10px; touch-action:pan-y; will-change:transform;
}
.wl-row.packed .row-fg{ background:var(--surf2); }

.wl-tick{
  flex:none; width:22px; height:22px; border-radius:50%; border:1.5px solid var(--border);
  display:flex; align-items:center; justify-content:center; font-size:13px; color:transparent;
}
.wl-tick.on{ background:var(--green); border-color:var(--green); color:#fff; }

.wl-main{ flex:1; min-width:0; }
.wl-name{ display:block; font-size:15px; color:var(--t1); line-height:1.3; overflow-wrap:break-word; }
.wl-row.packed .wl-name{ color:var(--t2); }
.wl-price{ font-size:13px; margin-top:1px; }
.wl-price .std{ color:var(--t1); font-weight:700; }       /* near-black bold price  */
.wl-price .loyal{ color:var(--loyal); font-weight:700; }  /* loyalty price = purple */
.wl-price .was{ color:var(--t3); text-decoration:line-through; font-weight:400; margin-left:6px; }

.wl-qty{ flex:none; display:flex; align-items:center; border:1px solid var(--border); border-radius:9px; overflow:hidden; }
.wl-qty button{ width:30px; height:32px; border:0; background:var(--surf2); color:var(--t1); font-size:18px; line-height:1; cursor:pointer; }
.wl-qty .q-n{ min-width:24px; text-align:center; font-size:14px; font-weight:600; }

.wl-cap{
  flex:none; width:34px; height:34px; border:1px solid var(--border); border-radius:9px;
  background:var(--surf2); color:var(--t2); font-size:15px; cursor:pointer;
  display:flex; align-items:center; justify-content:center;
}
.wl-cap.barcode{ letter-spacing:1px; font-weight:800; }
.wl-cap.done{ background:var(--green); border-color:var(--green); color:#fff; }  /* captured = green */
.wl-cap.busy{ background:var(--surf); }
.wl-cap.queued{ background:#FDEBD2; border-color:var(--amber); color:var(--amber); }  /* offline queued */
.wl-cap.retake{ background:#FCE7E7; border-color:var(--red); color:var(--red); font-weight:700; }  /* ⚠ retake */
.spin{ display:inline-block; width:15px; height:15px; border:2px solid rgba(17,21,31,.18);
       border-top-color:var(--accent); border-radius:50%; animation:spin .7s linear infinite; }
@keyframes spin{ to{ transform:rotate(360deg); } }
.wl-del{ flex:none; width:24px; height:34px; border:0; background:transparent; color:var(--t3); font-size:14px; cursor:pointer; }
.wl-del:active{ color:var(--red); }

.basket-head{
  display:flex; justify-content:space-between; align-items:center;
  margin:16px 2px 8px; font-weight:700; font-size:14px; color:var(--t2);
}

/* toast */
.toast{
  position:fixed; left:50%; transform:translateX(-50%);
  bottom:calc(var(--nav-h) + env(safe-area-inset-bottom) + 14px);
  background:var(--t1); color:#fff; font-size:13px; padding:9px 14px; border-radius:10px;
  z-index:40; opacity:0; transition:opacity .2s; pointer-events:none; max-width:90%; text-align:center;
}
.toast.show{ opacity:.95; }

/* ===== Auth + backup/restore (Step 6) ===== */
.header-right{ display:flex; align-items:center; gap:10px; }
.user-chip{
  font-size:13px; font-weight:600; color:var(--t2); text-decoration:none;
  background:var(--surf2); border:1px solid var(--border); border-radius:999px; padding:6px 12px;
}

.wide-btn{
  display:block; width:100%; text-align:center; box-sizing:border-box;
  border:0; background:var(--accent); color:#fff; font-weight:600; font-size:15px;
  padding:13px; border-radius:11px; cursor:pointer; margin-bottom:10px;
}
.wide-btn.ghost{ background:var(--surf); color:var(--t1); border:1px solid var(--border); }

/* login page */
.login-body{ min-height:100vh; display:flex; }
.login-wrap{ margin:auto; width:100%; max-width:360px; padding:24px; }
.login-card{ background:var(--surf); border:1px solid var(--border); border-radius:16px; padding:24px; }
.login-brand{ font-size:24px; font-weight:700; text-align:center; }
.login-sub{ text-align:center; color:var(--t2); font-size:14px; margin:4px 0 18px; }
.login-card .field{ margin-bottom:12px; }
.login-card .field input{
  width:100%; box-sizing:border-box; font-size:16px; color:var(--t1); background:var(--surf);
  border:1px solid var(--border); border-radius:10px; padding:11px 12px;
}
.login-error{
  background:#FCE7E7; color:var(--red); border:1px solid #f3bcbc; border-radius:10px;
  padding:9px 12px; font-size:13px; font-weight:600; margin-bottom:14px; text-align:center;
}
.login-btn{
  width:100%; border:0; background:var(--accent); color:#fff; font-weight:700; font-size:16px;
  padding:13px; border-radius:11px; cursor:pointer; margin-top:6px;
}

/* ===== Finish shop + History (Step 6b) ===== */
.finish-bar{
  display:flex; align-items:center; justify-content:space-between; gap:12px;
  margin-top:16px; padding:14px 16px;
  background:var(--surf); border:1px solid var(--border); border-radius:14px;
}
.finish-total{ font-size:15px; color:var(--t2); }
.finish-total strong{ color:var(--t1); font-size:19px; font-weight:700; margin-left:4px; }
.finish-btn{
  flex:none; border:0; background:var(--green); color:#fff; font-weight:700; font-size:15px;
  padding:12px 18px; border-radius:11px; cursor:pointer;
}

.history-list{ list-style:none; margin:0 0 14px; padding:0; }
.hist-row{
  background:var(--surf); border:1px solid var(--border); border-radius:12px;
  margin-bottom:8px; overflow:hidden;
}
.hist-head{
  width:100%; border:0; background:none; cursor:pointer; text-align:left;
  display:flex; align-items:center; justify-content:space-between; gap:10px; padding:13px 14px;
}
.hist-main{ display:flex; flex-direction:column; gap:2px; min-width:0; }
.hist-supplier{ font-size:15px; font-weight:600; color:var(--t1); }
.hist-meta{ font-size:12px; color:var(--t2); }
.hist-total{ font-size:17px; font-weight:700; color:var(--t1); flex:none; }
.hbadge{
  font-size:10px; font-weight:700; color:#fff; background:var(--loyal);
  border-radius:999px; padding:2px 7px; vertical-align:middle; text-transform:uppercase; letter-spacing:.03em;
}
.hist-head.open{ border-bottom:1px solid var(--border); }
.hist-body{ padding:6px 14px 12px; }
.hitem{
  display:grid; grid-template-columns:1fr auto auto; align-items:baseline; gap:8px;
  padding:7px 0; border-top:1px solid var(--surf2); font-size:14px;
}
.hitem:first-child{ border-top:0; }
.hitem-name{ color:var(--t1); }
.hitem-qty{ color:var(--t2); font-size:13px; }
.hitem-price{ color:var(--t1); font-weight:700; }
.hitem-extra{ grid-column:1 / -1; color:var(--t3); font-size:12px; margin-top:-2px; }
.hloy{
  font-size:11px; font-weight:700; color:var(--loyal);
  background:#F1E9FB; border-radius:6px; padding:1px 6px; margin-left:4px;
}

/* ===== Drafts (shared) ===== */
.draft-bar{ display:flex; align-items:center; justify-content:space-between; gap:10px; margin:0 0 12px; }
.draft-status{ font-size:13px; color:var(--t2); }
.draft-save{ flex:none; border:1px solid var(--border); background:var(--surf); color:var(--t1);
  font-weight:600; font-size:13px; padding:8px 12px; border-radius:10px; cursor:pointer; }

.keep-toggle{ display:flex; align-items:center; gap:8px; font-size:13px; color:var(--t2); margin-bottom:14px; }
.keep-toggle input{ width:16px; height:16px; }

.drafts-list{ list-style:none; margin:0; padding:0; }
.draft-row{ background:var(--surf); border:1px solid var(--border); border-radius:12px; margin-bottom:8px; overflow:hidden; }
.draft-head{ width:100%; border:0; background:none; cursor:pointer; text-align:left;
  display:flex; align-items:center; justify-content:space-between; gap:10px; padding:13px 14px; }
.draft-main{ display:flex; flex-direction:column; gap:2px; min-width:0; }
.draft-name{ font-size:15px; font-weight:600; color:var(--t1); }
.draft-meta{ font-size:12px; color:var(--t2); }
.draft-caret{ color:var(--t3); font-size:20px; line-height:1; flex:none; }
.draft-actions{ display:flex; gap:8px; padding:0 14px 12px; }
.draft-act{ flex:1; border:1px solid var(--border); background:var(--surf2); color:var(--t1);
  font-weight:600; font-size:13px; padding:9px; border-radius:9px; cursor:pointer; }
.draft-act.d-load{ background:var(--accent); border-color:var(--accent); color:#fff; }
.draft-act.d-del{ color:var(--red); }

/* ===== Receipt capture (Phase 2 Stage A) ===== */
.finish-actions{ display:flex; gap:8px; }
.finish-actions .receipt-btn, .finish-actions .finish-btn{ flex:1; padding:12px 8px; }
.receipt-btn{ border:1px solid var(--accent); background:var(--surf); color:var(--accent);
  font-weight:700; font-size:14px; border-radius:11px; cursor:pointer; }

.hist-receipt{ font-size:13px; }
.rc-action{ display:block; width:100%; margin-top:10px; border:1px solid var(--border);
  background:var(--surf2); color:var(--t1); font-weight:600; font-size:14px; padding:11px; border-radius:10px; cursor:pointer; }
.rc-action.add{ border-color:var(--accent); color:var(--accent); background:var(--surf); }

body.modal-open{ overflow:hidden; }
.rc-modal{ position:fixed; inset:0; z-index:60; background:rgba(17,21,31,.45); display:flex; }
.rc-sheet{ background:var(--bg); width:100%; max-width:560px; margin:auto; max-height:92vh;
  display:flex; flex-direction:column; border-radius:16px; overflow:hidden; box-shadow:0 12px 40px rgba(0,0,0,.25); }
@media (max-width:560px){ .rc-sheet{ margin:0; max-height:100vh; border-radius:0; } }
.rc-head{ display:flex; align-items:center; justify-content:space-between; gap:10px; padding:12px 14px;
  background:var(--surf); border-bottom:1px solid var(--border); }
.rc-title{ font-weight:700; font-size:16px; }
.rc-x{ border:0; background:none; font-size:18px; color:var(--t2); cursor:pointer; width:32px; height:32px; }
.rc-save{ border:0; background:var(--green); color:#fff; font-weight:700; font-size:14px; padding:8px 16px; border-radius:10px; cursor:pointer; }
.rc-body{ padding:14px 16px calc(env(safe-area-inset-bottom) + 24px); overflow-y:auto; }
.rc-body .field{ margin-bottom:10px; }
.rc-body .field input{ width:100%; box-sizing:border-box; font-size:15px; color:var(--t1);
  background:var(--surf); border:1px solid var(--border); border-radius:10px; padding:10px 12px; }
.rc-section{ display:flex; align-items:center; justify-content:space-between; margin:16px 2px 8px;
  font-weight:700; font-size:12px; color:var(--t2); text-transform:uppercase; letter-spacing:.05em; }
.rc-add{ border:1px solid var(--border); background:var(--surf); color:var(--accent); font-weight:700;
  font-size:12px; padding:5px 10px; border-radius:8px; cursor:pointer; text-transform:none; letter-spacing:0; }
.rc-line{ display:flex; gap:6px; margin-bottom:6px; align-items:center; }
.rc-line .rc-name{ flex:1; min-width:0; }
.rc-line input{ font-size:14px; color:var(--t1); background:var(--surf); border:1px solid var(--border);
  border-radius:9px; padding:9px 10px; box-sizing:border-box; }
.rc-line .rc-qty{ width:52px; text-align:center; }
.rc-line .rc-amt{ width:74px; text-align:right; }
.rc-del{ border:0; background:none; color:var(--t3); font-size:14px; width:26px; cursor:pointer; flex:none; }

.rv-img{ display:block; width:100%; border:1px solid var(--border); border-radius:10px; margin-bottom:14px; background:var(--surf2); }
.rv-lines{ font-size:14px; }
.rv-store{ font-weight:700; font-size:15px; margin-bottom:8px; }
.rv-line{ display:flex; justify-content:space-between; gap:10px; padding:6px 0; border-top:1px solid var(--surf2); }
.rv-line:first-of-type{ border-top:0; }
.rv-line.disc{ color:var(--loyal); }
.rv-line.tot{ color:var(--t2); }
.rv-line.tot.grand{ color:var(--t1); font-weight:700; font-size:16px; border-top:1px solid var(--border); margin-top:4px; }
