/* Shop Sales — shared styles. Mobile-first, calm, high-contrast, big tap targets. */
:root {
  --bg: #f4f6f8;
  --card: #ffffff;
  --ink: #16191d;
  --muted: #6b7480;
  --line: #e4e8ec;
  --primary: #1f4fd8;
  --primary-ink: #ffffff;
  --primary-soft: #eaf0ff;
  --good: #0f9d58;
  --good-soft: #e7f6ee;
  --warn: #b45309;
  --danger: #d13a3a;
  --danger-soft: #fdecec;
  --radius: 14px;
  --shadow: 0 1px 2px rgba(16,25,40,.06), 0 6px 20px rgba(16,25,40,.06);
}
* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  background: var(--bg);
  color: var(--ink);
  -webkit-font-smoothing: antialiased;
  font-size: 16px;
  line-height: 1.4;
}
.wrap { max-width: 560px; margin: 0 auto; padding: 0 16px 96px; }
.hidden { display: none !important; }

/* Header */
.appbar {
  position: sticky; top: 0; z-index: 20;
  background: var(--card);
  border-bottom: 1px solid var(--line);
}
.appbar-inner {
  max-width: 560px; margin: 0 auto; padding: 12px 16px;
  display: flex; align-items: center; gap: 12px;
}
.appbar .brand { font-weight: 700; font-size: 17px; letter-spacing: -.01em; }
.appbar .brand small { display:block; font-weight: 500; color: var(--muted); font-size: 12px; }
.appbar .spacer { flex: 1; }

.sync-pill {
  display: inline-flex; align-items: center; gap: 6px;
  border: 1px solid var(--line); background: #fff;
  border-radius: 999px; padding: 7px 12px; font-size: 13px; font-weight: 600;
  color: var(--ink); cursor: pointer; white-space: nowrap;
}
.sync-pill .dot { width: 8px; height: 8px; border-radius: 50%; background: var(--good); }
.sync-pill.pending { color: var(--warn); border-color: #f3d9b0; background: #fff8ee; }
.sync-pill.pending .dot { background: var(--warn); }

.link-btn { background: none; border: none; color: var(--primary); font-weight: 600; cursor: pointer; font-size: 14px; padding: 6px; }

/* Cards */
.card {
  background: var(--card); border: 1px solid var(--line);
  border-radius: var(--radius); box-shadow: var(--shadow);
  padding: 18px; margin-top: 16px;
}
h1 { font-size: 22px; margin: 20px 0 4px; letter-spacing: -.02em; }
h2 { font-size: 17px; margin: 0 0 12px; }
.sub { color: var(--muted); font-size: 14px; margin: 0 0 12px; }

/* Forms */
label { display: block; font-weight: 600; font-size: 14px; margin: 14px 0 6px; }
input[type=text], input[type=password], input[type=number], input[type=tel], input[type=date], select {
  width: 100%; padding: 14px; font-size: 17px;
  border: 1.5px solid var(--line); border-radius: 12px; background: #fff; color: var(--ink);
  -webkit-appearance: none; appearance: none;
}
input:focus, select:focus { outline: none; border-color: var(--primary); box-shadow: 0 0 0 3px var(--primary-soft); }
.row2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.money-in { position: relative; }
.money-in::before { content: "Rs"; position: absolute; left: 12px; top: 50%; transform: translateY(-50%); color: var(--muted); font-size: 14px; font-weight: 600; pointer-events: none; }
.money-in input { padding-left: 40px; }

/* Buttons */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  width: 100%; padding: 16px; font-size: 17px; font-weight: 700;
  border-radius: 12px; border: 1.5px solid transparent; cursor: pointer; margin-top: 14px;
}
.btn.primary { background: var(--primary); color: var(--primary-ink); }
.btn.primary:active { filter: brightness(.95); }
.btn.ghost { background: #fff; color: var(--ink); border-color: var(--line); }
.btn.subtle { background: var(--primary-soft); color: var(--primary); }
.btn.danger { background: var(--danger-soft); color: var(--danger); }
.btn.good { background: var(--good); color: #fff; }
.btn:disabled { opacity: .5; }
.btn-row { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.btn.small { width: auto; padding: 10px 14px; font-size: 14px; margin: 0; }

/* Switch */
.switch-row { display: flex; align-items: center; justify-content: space-between; margin-top: 18px; padding: 4px 0; }
.switch-row .switch-label { font-weight: 700; font-size: 16px; }
.switch { position: relative; width: 52px; height: 30px; flex: none; }
.switch input { opacity: 0; width: 0; height: 0; }
.slider { position: absolute; inset: 0; background: #cfd6dd; border-radius: 999px; transition: .15s; }
.slider::before { content:""; position:absolute; width: 24px; height: 24px; left: 3px; top: 3px; background:#fff; border-radius:50%; transition:.15s; box-shadow: 0 1px 3px rgba(0,0,0,.2); }
.switch input:checked + .slider { background: var(--primary); }
.switch input:checked + .slider::before { transform: translateX(22px); }

/* Total-to-collect preview strip (the shop shows the amount to collect here) */
.total-strip {
  margin-top: 16px; padding: 14px 16px; border-radius: 12px;
  background: var(--good-soft); color: var(--good);
  display: flex; align-items: center; justify-content: space-between; font-weight: 700;
  font-size: 18px;
}

/* Summary rows */
.sum-line { display: flex; justify-content: space-between; padding: 8px 0; border-bottom: 1px dashed var(--line); font-size: 15px; }
.sum-line:last-child { border-bottom: none; }
.sum-line .k { color: var(--muted); }
.sum-line.total { font-weight: 800; font-size: 18px; border-top: 2px solid var(--line); margin-top: 4px; padding-top: 12px; }

/* Totals tiles */
.tiles { display: grid; grid-template-columns: repeat(3,1fr); gap: 10px; margin-top: 16px; }
.tile { background: var(--card); border: 1px solid var(--line); border-radius: 12px; padding: 14px; text-align: center; box-shadow: var(--shadow); }
.tile .n { font-size: 20px; font-weight: 800; letter-spacing: -.02em; }
.tile .l { font-size: 12px; color: var(--muted); margin-top: 2px; }
.tile.good .n { color: var(--good); }
.tile.profit .n { color: var(--primary); }

/* Sale list */
.sale { background: var(--card); border: 1px solid var(--line); border-radius: 12px; padding: 14px; margin-top: 10px; box-shadow: var(--shadow); }
.sale .top { display: flex; justify-content: space-between; align-items: baseline; }
.sale .time { color: var(--muted); font-size: 13px; }
.sale .amt { font-weight: 800; font-size: 17px; }
.sale .meta { color: var(--muted); font-size: 13px; margin-top: 4px; }
.sale .pf { color: var(--good); font-weight: 700; font-size: 13px; }
.sale .acts { display: flex; gap: 8px; margin-top: 10px; }
.sale.deleted { opacity: .5; }
.badge { display:inline-block; font-size: 11px; font-weight: 700; padding: 2px 8px; border-radius: 999px; background: var(--primary-soft); color: var(--primary); }

/* Tabs */
.tabs { display: flex; gap: 8px; margin-top: 16px; background: #eef1f4; padding: 5px; border-radius: 12px; }
.tab { flex: 1; text-align: center; padding: 10px; border-radius: 9px; font-weight: 700; color: var(--muted); cursor: pointer; }
.tab.active { background: #fff; color: var(--ink); box-shadow: var(--shadow); }

/* Toast / message */
.msg { margin-top: 14px; padding: 12px 14px; border-radius: 10px; font-size: 14px; font-weight: 600; }
.msg.ok { background: var(--good-soft); color: var(--good); }
.msg.err { background: var(--danger-soft); color: var(--danger); }
.msg.info { background: var(--primary-soft); color: var(--primary); }

.pin-input { text-align: center; letter-spacing: 8px; font-size: 24px; font-weight: 800; }
.empty { text-align: center; color: var(--muted); padding: 30px 10px; }
.center { text-align: center; }
.big-check { width: 72px; height: 72px; border-radius: 50%; background: var(--good-soft); color: var(--good); display: flex; align-items: center; justify-content: center; font-size: 40px; margin: 6px auto 12px; }
.shop-pick { width:100%; text-align:left; padding: 16px; font-size: 17px; font-weight: 700; border:1.5px solid var(--line); background:#fff; border-radius: 12px; margin-top: 10px; cursor: pointer; }
.shop-pick:active { border-color: var(--primary); }
.footnote { color: var(--muted); font-size: 12px; margin-top: 10px; text-align: center; }
.settings-row { display:flex; gap: 10px; align-items:center; flex-wrap: wrap; }

/* Admin table */
.table-scroll { overflow-x: auto; margin-top: 12px; -webkit-overflow-scrolling: touch; }
table { width: 100%; border-collapse: collapse; font-size: 14px; min-width: 1180px; }
th, td { text-align: right; padding: 10px 12px; border-bottom: 1px solid var(--line); white-space: nowrap; vertical-align: top; }
th:first-child, td:first-child, th.l, td.l { text-align: left; }
thead th { color: var(--muted); font-weight: 700; font-size: 12px; text-transform: uppercase; letter-spacing: .03em; position: sticky; top: 0; background: var(--card); }
tbody tr:hover { background: #fafbfc; }
td.tot { font-weight: 800; }
td.pf { color: var(--good); font-weight: 800; }
.filters { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; margin-top: 8px; }
.chip { padding: 8px 14px; border-radius: 999px; border: 1.5px solid var(--line); background: #fff; font-weight: 700; font-size: 14px; cursor: pointer; color: var(--muted); }
.chip.active { background: var(--primary); color: #fff; border-color: var(--primary); }
.select-inline { width: auto; min-width: 160px; padding: 9px 12px; font-size: 14px; }
.admin-wrap { max-width: 1000px; }

/* Sales date-range control + shop filter row */
.sales-controls { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; margin-top: 10px; }
.range-trigger {
  display: inline-flex; align-items: center; gap: 8px;
  padding: 10px 14px; border: 1.5px solid var(--line); border-radius: 12px;
  background: #fff; color: var(--ink); font-weight: 700; font-size: 14px; cursor: pointer;
}
.range-trigger:active { border-color: var(--primary); }
.range-trigger .rt-icon { font-size: 15px; }
.range-trigger .rt-caret { color: var(--muted); font-size: 11px; }

/* Range picker modal (scrim + centered panel) — mirrors the drawer's scrim. */
.range-scrim { position: fixed; inset: 0; background: rgba(16,25,40,.4); z-index: 70; opacity: 0; pointer-events: none; transition: opacity .18s ease; }
.range-scrim.open { opacity: 1; pointer-events: auto; }
.range-panel {
  position: fixed; z-index: 80; left: 50%; top: 50%; transform: translate(-50%, -46%);
  width: min(680px, 94vw); max-height: 90vh; overflow: auto;
  background: var(--card); border: 1px solid var(--line); border-radius: 16px;
  box-shadow: 0 12px 48px rgba(16,25,40,.24);
  opacity: 0; pointer-events: none; transition: opacity .18s ease, transform .18s ease;
}
.range-panel.open { opacity: 1; pointer-events: auto; transform: translate(-50%, -50%); }
.range-head { display: flex; align-items: center; justify-content: space-between; padding: 14px 16px; border-bottom: 1px solid var(--line); font-weight: 800; font-size: 16px; }
.range-body { display: flex; gap: 14px; padding: 14px 16px; }
.preset-list { display: flex; flex-direction: column; gap: 6px; width: 150px; flex: none; }
.qp { text-align: left; padding: 11px 12px; border: 1.5px solid var(--line); background: #fff; border-radius: 10px; font-weight: 700; font-size: 13px; color: var(--ink); cursor: pointer; }
.qp:active { background: var(--bg); }
.qp.active { background: var(--primary); color: #fff; border-color: var(--primary); }

/* Self-contained calendar (no external lib). */
.cal { flex: 1; min-width: 0; }
.cal-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 10px; }
.cal-title { font-weight: 800; font-size: 15px; }
.cal-nav { width: 36px; height: 36px; border: 1.5px solid var(--line); background: #fff; border-radius: 9px; font-size: 18px; line-height: 1; cursor: pointer; color: var(--ink); }
.cal-nav:disabled { opacity: .4; cursor: default; }
.cal-dow { display: grid; grid-template-columns: repeat(7, 1fr); gap: 2px; margin-bottom: 4px; }
.cal-dow span { text-align: center; font-size: 11px; font-weight: 700; color: var(--muted); padding: 4px 0; }
.cal-grid { display: grid; grid-template-columns: repeat(7, 1fr); gap: 2px; }
.cal-cell { aspect-ratio: 1; min-height: 38px; }
.cal-cell.empty { visibility: hidden; }
.cal-cell.day {
  display: flex; align-items: center; justify-content: center;
  border: none; background: transparent; border-radius: 9px;
  font-size: 14px; font-weight: 600; color: var(--ink); cursor: pointer; padding: 0;
}
.cal-cell.day:hover { background: var(--primary-soft); }
.cal-cell.day.today { box-shadow: inset 0 0 0 1.5px var(--muted); }
.cal-cell.day.in-range { background: var(--primary-soft); border-radius: 0; }
.cal-cell.day.sel-start, .cal-cell.day.sel-end { background: var(--primary); color: #fff; }
.cal-cell.day.sel-start { border-radius: 9px 0 0 9px; }
.cal-cell.day.sel-end { border-radius: 0 9px 9px 0; }
.cal-cell.day.sel-start.sel-end { border-radius: 9px; }
.cal-cell.day.disabled { color: var(--line); cursor: default; pointer-events: none; }

.range-foot { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 12px 16px; border-top: 1px solid var(--line); flex-wrap: wrap; }
.picker-sel { font-weight: 700; font-size: 14px; color: var(--muted); }
.range-foot-btns { display: flex; gap: 8px; }
.range-foot-btns .btn.small { margin: 0; }

/* Phone: the quick-pick sidebar becomes a wrapping row above the calendar. */
@media (max-width: 560px) {
  .range-body { flex-direction: column; gap: 10px; }
  .preset-list { flex-direction: row; flex-wrap: wrap; width: auto; }
  .qp { flex: 1 1 30%; text-align: center; }
}

/* Admin drawer nav — landing view is sales-only; other sections open from here */
.icon-btn { background: none; border: none; font-size: 22px; line-height: 1; padding: 6px 4px; margin: 0; cursor: pointer; color: var(--ink); flex: none; }
.drawer {
  position: fixed; top: 0; left: 0; height: 100%; width: 78%; max-width: 300px;
  background: var(--card); z-index: 60; transform: translateX(-100%);
  transition: transform .22s ease; box-shadow: 2px 0 24px rgba(16,25,40,.14);
  display: flex; flex-direction: column;
  padding: 6px 8px calc(8px + env(safe-area-inset-bottom));
}
.drawer.open { transform: translateX(0); }
.drawer-head { font-weight: 800; font-size: 18px; padding: 16px 12px 8px; letter-spacing: -.01em; }
.drawer-item {
  display: block; width: 100%; text-align: left; background: none; border: none;
  border-radius: 10px; padding: 14px 12px; font-size: 16px; font-weight: 700;
  color: var(--ink); cursor: pointer;
}
.drawer-item:active { background: var(--bg); }
.drawer-item.active { background: var(--primary-soft); color: var(--primary); }
.drawer-scrim {
  position: fixed; inset: 0; background: rgba(16,25,40,.4); z-index: 50;
  opacity: 0; pointer-events: none; transition: opacity .22s ease;
}
.drawer-scrim.open { opacity: 1; pointer-events: auto; }

/* Scan row + camera overlay */
.scan-row { display: flex; gap: 10px; align-items: stretch; flex-wrap: wrap; }
/* min-width:0 lets the field shrink to fit; without it a flex item keeps its
   intrinsic min-width (input default size) on iOS Safari / some Android WebViews
   and pushes the row past the card edge. flex-wrap drops Scan below only if truly
   cramped. Do not remove min-width:0 — it looks redundant but prevents overflow. */
.scan-row input { flex: 1 1 55%; min-width: 0; }
.scan-btn { width: auto; margin: 0; padding: 0 18px; white-space: nowrap; flex: none; }
.scanner { position: fixed; inset: 0; z-index: 100; background: #000; display: flex; align-items: center; justify-content: center; }
#scanVideo { width: 100%; height: 100%; object-fit: cover; }
.scan-frame { position: absolute; width: 66vw; max-width: 300px; aspect-ratio: 1; border: 3px solid #fff; border-radius: 16px; box-shadow: 0 0 0 100vmax rgba(0,0,0,.45); }
.scan-bar { position: absolute; bottom: 0; left: 0; right: 0; padding: 20px 16px calc(20px + env(safe-area-inset-bottom)); display: flex; align-items: center; justify-content: space-between; gap: 12px; background: linear-gradient(transparent, rgba(0,0,0,.7)); }
.scan-bar span { color: #fff; font-weight: 600; font-size: 15px; }
.sku-hit { color: var(--good); font-weight: 700; }
.thumb { width: 44px; height: 44px; border-radius: 8px; object-fit: cover; background: #eef1f4; border: 1px solid var(--line); flex: none; }
.prod-row { display: flex; align-items: center; gap: 12px; padding: 10px 0; border-bottom: 1px dashed var(--line); }
.prod-row:last-child { border-bottom: none; }
.prod-row .info { flex: 1; min-width: 0; }
.prod-row .sku { font-weight: 800; letter-spacing: .02em; }
.prod-row .sub2 { color: var(--muted); font-size: 13px; }
.prod-check, .pick-check { width: 22px; height: 22px; flex: none; accent-color: var(--primary); cursor: pointer; }
.selectall { display: inline-flex; align-items: center; gap: 8px; margin: 0; font-size: 14px; font-weight: 700; color: var(--muted); cursor: pointer; }
.selectall input { width: 20px; height: 20px; accent-color: var(--primary); cursor: pointer; }

/* Full-width product-photo placeholder: tap to capture/choose, shows a preview. */
.imagedrop {
  display: flex; align-items: center; justify-content: center;
  width: 100%; min-height: 150px; margin-top: 6px; padding: 16px;
  border: 2px dashed var(--line); border-radius: 12px; background: #fafbfc;
  color: var(--muted); text-align: center; cursor: pointer; overflow: hidden;
}
.imagedrop:active { border-color: var(--primary); background: var(--primary-soft); }
.imagedrop-hint { font-size: 14px; font-weight: 600; }
.imagedrop-img { width: 100%; max-height: 320px; object-fit: contain; border-radius: 8px; }

/* QR label printing now happens inside a self-contained print iframe (built in
   admin.js) that carries its own styles — reliable on mobile, unlike the old
   whole-page visibility hack. No print CSS is needed on the main document. */

/* Per-shop stock editor (tracked products) + add-product opening-stock inputs */
.stock-editor { margin: 2px 0 12px 34px; padding: 10px 12px; background: #fafbfc; border: 1px solid var(--line); border-radius: 10px; }
.stock-head { font-size: 12px; font-weight: 700; color: var(--muted); text-transform: uppercase; letter-spacing: .03em; margin-bottom: 6px; }
.stock-row { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 5px 0; }
.stock-shop { font-weight: 600; font-size: 14px; }
.stock-qty { width: 96px; flex: none; padding: 8px 10px; font-size: 15px; text-align: right; }
.stock-qty.neg { color: var(--danger); border-color: var(--danger); font-weight: 800; }

/* New-sale alert opt-in banner (admin). Shows until notifications are granted;
   the button is the user gesture that requests permission. */
.alert-optin {
  display: flex; align-items: center; gap: 14px; flex-wrap: wrap;
  margin-top: 14px; padding: 14px 16px;
  background: var(--primary-soft); border: 1px solid #cddcff; border-radius: 12px;
}
.alert-optin .optin-text { flex: 1 1 240px; min-width: 0; display: flex; flex-direction: column; gap: 3px; }
.alert-optin .optin-text strong { font-size: 15px; }
.alert-optin .optin-text span { color: var(--muted); font-size: 13px; }
.alert-optin .btn.small { flex: none; }

/* "New version — reload" bar (shared by shop + admin). Fixed + non-blocking;
   appears when a new service worker is deployed so an already-open page can pull
   the new code without the owner knowing to hard-reload. */
.sw-update-bar {
  position: fixed; left: 50%; bottom: calc(16px + env(safe-area-inset-bottom));
  transform: translateX(-50%); z-index: 90;
  display: flex; align-items: center; gap: 14px;
  max-width: calc(100vw - 24px);
  background: var(--ink); color: #fff;
  padding: 12px 14px 12px 18px; border-radius: 999px;
  box-shadow: 0 6px 24px rgba(16,25,40,.28);
  font-size: 14px; font-weight: 600;
}
.sw-update-bar .sw-update-btn {
  flex: none; border: none; cursor: pointer;
  background: #fff; color: var(--ink);
  font-weight: 800; font-size: 14px;
  padding: 8px 16px; border-radius: 999px;
}
.sw-update-bar .sw-update-btn:disabled { opacity: .6; }
