:root {
  --bg: #f6f4ee;
  --card: #ffffff;
  --ink: #1d2320;
  --muted: #5f6b65;
  --line: #e2ded3;
  --brand: #1f7a4d;
  --brand-ink: #ffffff;
  --brand-soft: #e3f1e9;
  --warn: #b45309;
  --warn-soft: #fdf1e2;
  --bad: #b42318;
  --bad-soft: #fde8e6;
  --good: #1f7a4d;
  --radius: 14px;
  --shadow: 0 2px 10px rgba(29, 35, 32, .08);
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  font-family: 'Mukta', system-ui, sans-serif;
  font-size: 16px; line-height: 1.45;
  background: var(--bg); color: var(--ink);
  -webkit-tap-highlight-color: transparent;
}
button, input, select, textarea { font: inherit; color: inherit; }
.hidden { display: none !important; }
.splash { display: grid; place-items: center; height: 100vh; font-size: 22px; font-weight: 700; color: var(--brand); }

/* layout */
#app { display: flex; flex-direction: column; min-height: 100vh; max-width: 640px; margin: 0 auto; background: var(--bg); }
.topbar {
  position: sticky; top: 0; z-index: 900;
  display: flex; align-items: center; gap: 10px;
  padding: 10px 16px; padding-top: max(10px, env(safe-area-inset-top));
  background: var(--brand); color: var(--brand-ink);
}
.topbar h1 { font-size: 19px; margin: 0; flex: 1; font-weight: 700; }
.topbar .sub { font-size: 13px; opacity: .85; display: block; font-weight: 400; }
.topbar button { background: rgba(255,255,255,.16); border: 0; color: #fff; border-radius: 10px; padding: 6px 10px; }
main { flex: 1; padding: 16px; padding-bottom: 96px; }
main.flush { padding: 0; padding-bottom: 72px; }
.tabs {
  position: fixed; bottom: 0; left: 50%; transform: translateX(-50%);
  width: 100%; max-width: 640px; z-index: 900;
  display: flex; background: var(--card); border-top: 1px solid var(--line);
  padding-bottom: env(safe-area-inset-bottom);
}
.tabs button {
  flex: 1; border: 0; background: none; padding: 10px 4px 8px; font-size: 13px; color: var(--muted);
  display: flex; flex-direction: column; align-items: center; gap: 2px;
}
.tabs button .ic { font-size: 20px; line-height: 1; }
.tabs button.on { color: var(--brand); font-weight: 700; }
.tabs .badge { background: var(--bad); color: #fff; border-radius: 99px; font-size: 11px; padding: 0 6px; margin-left: 2px; }

/* cards, forms */
.card { background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow); padding: 14px; margin-bottom: 12px; }
.card h3 { margin: 0 0 6px; font-size: 17px; }
.row { display: flex; align-items: center; gap: 10px; }
.row.between { justify-content: space-between; }
.grow { flex: 1; min-width: 0; }
.muted { color: var(--muted); font-size: 14px; }
.small { font-size: 13px; }
.stack > * + * { margin-top: 10px; }
label { display: block; font-size: 14px; font-weight: 600; margin-bottom: 4px; }
input, select, textarea {
  width: 100%; padding: 11px 12px; border: 1px solid var(--line); border-radius: 10px; background: #fff;
}
input:focus, select:focus, textarea:focus { outline: 2px solid var(--brand); outline-offset: 0; border-color: transparent; }
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  border: 0; border-radius: 12px; padding: 12px 16px; font-weight: 700; cursor: pointer;
  background: var(--brand); color: var(--brand-ink); text-decoration: none;
}
.btn.block { width: 100%; }
.btn.ghost { background: var(--brand-soft); color: var(--brand); }
.btn.danger { background: var(--bad-soft); color: var(--bad); }
.btn.small { padding: 7px 12px; font-size: 14px; border-radius: 10px; }
.btn:disabled { opacity: .5; }
.link { background: none; border: 0; color: var(--brand); font-weight: 700; padding: 0; cursor: pointer; }
.pill { display: inline-block; padding: 2px 10px; border-radius: 99px; font-size: 13px; font-weight: 600; background: var(--brand-soft); color: var(--brand); }
.pill.warn { background: var(--warn-soft); color: var(--warn); }
.pill.bad { background: var(--bad-soft); color: var(--bad); }
.pill.grey { background: #eceae4; color: var(--muted); }
.seg { display: flex; background: #eceae4; border-radius: 12px; padding: 4px; gap: 4px; }
.seg button { flex: 1; border: 0; border-radius: 9px; padding: 8px; background: none; font-weight: 600; color: var(--muted); }
.seg button.on { background: #fff; color: var(--ink); box-shadow: var(--shadow); }
.empty { text-align: center; color: var(--muted); padding: 32px 12px; }
hr { border: 0; border-top: 1px solid var(--line); margin: 12px 0; }

/* auth */
.auth { padding: 24px 16px 40px; }
.brand-hero { text-align: center; margin: 12px 0 20px; }
.brand-hero .logo { font-size: 44px; }
.brand-hero h2 { margin: 4px 0 0; font-size: 28px; color: var(--brand); }

/* map screen */
.map-wrap { position: relative; height: calc(100vh - 56px - 64px); }
#bigmap { position: absolute; inset: 0; }
.map-tools { position: absolute; top: 10px; left: 10px; right: 10px; z-index: 800; }
.guest-bar { gap: 8px; margin-bottom: 8px; } .guest-bar select { flex: 1; min-width: 0; background: var(--card); box-shadow: 0 2px 8px rgba(0,0,0,.12); } .guest-bar .btn { background: var(--card); white-space: nowrap; box-shadow: 0 2px 8px rgba(0,0,0,.12); }
.searchbox { display: flex; gap: 8px; background: #fff; border-radius: 12px; box-shadow: var(--shadow); padding: 4px 4px 4px 12px; align-items: center; }
.searchbox input { border: 0; padding: 8px 0; }
.searchbox input:focus { outline: none; }
.chips { display: flex; gap: 6px; overflow-x: auto; padding: 8px 0 2px; scrollbar-width: none; }
.chips::-webkit-scrollbar { display: none; }
.chip { flex: none; border: 0; background: #fff; border-radius: 99px; padding: 6px 12px; box-shadow: var(--shadow); font-size: 14px; white-space: nowrap; }
.chip.on { background: var(--brand); color: #fff; }
.result-count { position: absolute; left: 10px; bottom: 12px; z-index: 800; background: #fff; border-radius: 99px; padding: 4px 12px; box-shadow: var(--shadow); font-size: 13px; }
.cart-fab { position: absolute; right: 12px; bottom: 12px; z-index: 800; box-shadow: 0 4px 14px rgba(0,0,0,.2); }
.shop-pin {
  background: #fff; border: 2px solid var(--brand); border-radius: 50% 50% 50% 4px; transform: rotate(-45deg);
  width: 38px; height: 38px; display: grid; place-items: center; box-shadow: 0 2px 6px rgba(0,0,0,.25);
}
.shop-pin span { transform: rotate(45deg); font-size: 19px; }
.shop-pin.closed { border-color: #9aa39e; filter: grayscale(1); opacity: .75; }
.pin-label { background: #fff; border-radius: 6px; padding: 0 6px; font-size: 12px; font-weight: 600; white-space: nowrap; box-shadow: 0 1px 3px rgba(0,0,0,.2); }
.boy-pin { font-size: 28px; filter: drop-shadow(0 2px 2px rgba(0,0,0,.35)); }
.home-pin { font-size: 26px; filter: drop-shadow(0 2px 2px rgba(0,0,0,.35)); }
.minimap { height: 220px; border-radius: 12px; overflow: hidden; border: 1px solid var(--line); }
.trackmap { height: 260px; border-radius: 12px; overflow: hidden; border: 1px solid var(--line); }

/* bottom sheet */
#sheet-backdrop { position: fixed; inset: 0; background: rgba(0,0,0,.35); z-index: 1000; }
#sheet {
  position: fixed; left: 50%; transform: translateX(-50%); bottom: 0; z-index: 1001;
  width: 100%; max-width: 640px; max-height: 88vh; overflow-y: auto;
  background: var(--bg); border-radius: 18px 18px 0 0; padding: 8px 16px 24px;
  padding-bottom: max(24px, env(safe-area-inset-bottom));
}
#sheet .grab { width: 44px; height: 5px; border-radius: 99px; background: #cfcabd; margin: 4px auto 12px; }
.prod { display: flex; align-items: center; gap: 10px; padding: 10px 0; border-bottom: 1px solid var(--line); }
.prod:last-child { border-bottom: 0; }
.qty { display: flex; align-items: center; gap: 6px; }
.qty button { width: 34px; height: 34px; border-radius: 10px; border: 0; background: var(--brand-soft); color: var(--brand); font-size: 20px; font-weight: 700; }
.qty b { min-width: 22px; text-align: center; }
.price { font-weight: 700; }

/* orders */
.order-item { cursor: pointer; }
.timeline { list-style: none; padding: 0; margin: 0; }
.timeline li { position: relative; padding: 0 0 12px 22px; font-size: 14px; }
.timeline li::before { content: ''; position: absolute; left: 5px; top: 7px; width: 9px; height: 9px; border-radius: 50%; background: var(--brand); }
.timeline li::after { content: ''; position: absolute; left: 9px; top: 18px; bottom: 0; width: 1px; background: var(--line); }
.timeline li:last-child::after { display: none; }
.otp-box { text-align: center; background: var(--brand-soft); border-radius: var(--radius); padding: 16px; }
.otp-box .otp { font-size: 40px; letter-spacing: 12px; font-weight: 700; color: var(--brand); }
.qr-box { display: grid; place-items: center; padding: 12px; background: #fff; border-radius: 12px; border: 1px solid var(--line); }
.qr-box img, .qr-box canvas { width: 220px !important; height: 220px !important; }
.proof-img { width: 100%; border-radius: 12px; border: 1px solid var(--line); }
.live-dot { display: inline-block; width: 9px; height: 9px; border-radius: 50%; background: var(--bad); margin-right: 6px; animation: pulse 1.2s infinite; }
@keyframes pulse { 50% { opacity: .25; } }

.stars { display: flex; gap: 2px; margin: 4px 0 6px; }
.stars button { border: 0; background: none; font-size: 30px; line-height: 1; color: #d6d1c4; padding: 0 2px; cursor: pointer; }
.stars button.on { color: #f0a92b; }

/* admin report */
.kpis { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin-bottom: 12px; }
.kpi { background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow); padding: 10px; }
.kpi .k { font-size: 13px; color: var(--muted); }
.kpi .v { font-size: 20px; font-weight: 700; line-height: 1.2; }
.kpi .s { font-size: 12px; color: var(--muted); }
.kpi.on { outline: 2px solid var(--brand); }
.bars { display: flex; align-items: flex-end; gap: 2px; height: 120px; padding-top: 8px; border-bottom: 1px solid var(--line); }
.bars div { flex: 1; background: var(--brand); border-radius: 3px 3px 0 0; min-height: 1px; opacity: .85; }
.bars div.today { background: #f0a92b; }
.tbl { width: 100%; border-collapse: collapse; font-size: 14px; }
.tbl th { text-align: left; color: var(--muted); font-weight: 600; font-size: 12px; padding: 4px 4px; border-bottom: 1px solid var(--line); }
.tbl td { padding: 6px 4px; border-bottom: 1px solid var(--line); }
.tbl td.r, .tbl th.r { text-align: right; }
.person { display: flex; align-items: center; gap: 10px; }
.person.off { opacity: .6; }

#toast {
  position: fixed; left: 50%; top: 72px; transform: translateX(-50%); z-index: 2000; text-align: center;
  background: #1d2320; color: #fff; padding: 10px 16px; border-radius: 12px; max-width: 90vw; font-size: 15px;
  box-shadow: 0 6px 20px rgba(0,0,0,.25);
}
#toast.err { background: var(--bad); }

/* signup role cards */
.role-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-bottom: 16px; }
.role-card { border: 1px solid var(--line); background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow);
  padding: 16px 10px; display: flex; flex-direction: column; align-items: center; gap: 2px; cursor: pointer; text-align: center; }
.role-card .ic { font-size: 34px; }
.role-card b { font-size: 17px; }
.stock { font-size: 12px; color: var(--muted); }
.stock.low { color: var(--warn); font-weight: 600; }

/* nav brand (desktop only), map extras, shopping list */
.nav-brand { display: none; }
.map-list { display: none; }
.map-btns { position: absolute; left: 10px; bottom: 48px; z-index: 800; display: flex; gap: 6px; }
.map-btns .btn { box-shadow: var(--shadow); }
.list-item .qty button { width: 30px; height: 30px; font-size: 18px; }
.list-grid > div + div { margin-top: 16px; }

/* ============================================================ DESKTOP */
@media (min-width: 960px) {
  body { background: #ecebe4; }
  #app:has(> nav.tabs) {
    max-width: none; display: grid; grid-template-columns: 232px minmax(0, 1fr);
    grid-template-rows: auto 1fr; min-height: 100vh;
  }
  #app:has(> nav.tabs) > .topbar { grid-column: 2; grid-row: 1; padding: 14px 32px; }
  #app:has(> nav.tabs) > main { grid-column: 2; grid-row: 2; width: 100%; max-width: 1180px; margin: 0 auto; padding: 24px 32px 48px; }
  #app:has(> nav.tabs) > main.flush { max-width: none; padding: 0; }
  .topbar h1 { font-size: 22px; }
  .topbar .sub { display: inline; margin-left: 12px; }

  /* bottom tabs → left sidebar */
  .tabs {
    grid-column: 1; grid-row: 1 / span 2; position: sticky; top: 0; left: auto; transform: none;
    height: 100vh; max-width: none; flex-direction: column; justify-content: flex-start; gap: 2px;
    border-top: 0; border-right: 1px solid var(--line); padding: 0 12px 16px;
  }
  .nav-brand { display: block; font-size: 22px; font-weight: 700; color: var(--brand); padding: 18px 10px 16px; margin: 0 -12px 8px; border-bottom: 1px solid var(--line); padding-left: 22px; }
  .nav-brand span { display: block; font-size: 13px; font-weight: 400; color: var(--muted); }
  .tabs button { flex: none; flex-direction: row; justify-content: flex-start; gap: 12px; padding: 11px 12px; font-size: 16px; border-radius: 10px; cursor: pointer; }
  .tabs button:hover { background: var(--bg); }
  .tabs button.on { background: var(--brand-soft); }
  .tabs button .ic { font-size: 20px; width: 24px; text-align: center; }

  /* map + result list side by side */
  .map-wrap { height: calc(100vh - 64px); }
  #bigmap { left: 360px; }
  .map-tools { left: 372px; right: 16px; max-width: 760px; }
  .result-count { display: none; }
  .map-btns { left: 376px; bottom: 16px; }
  .map-list { display: block; position: absolute; left: 0; top: 0; bottom: 0; width: 360px; overflow-y: auto; background: var(--card); border-right: 1px solid var(--line); z-index: 700; }
  .ml-head { position: sticky; top: 0; background: var(--card); padding: 14px 16px; font-weight: 700; border-bottom: 1px solid var(--line); }
  .ml-item { display: flex; flex-direction: column; align-items: flex-start; gap: 2px; width: 100%; text-align: left; border: 0; border-bottom: 1px solid var(--line); background: none; padding: 12px 16px; cursor: pointer; }
  .ml-item:hover { background: var(--bg); }

  /* bottom sheet → right-side panel */
  #sheet { left: auto; right: 0; top: 0; bottom: 0; transform: none; max-width: 480px; max-height: none; height: 100vh; border-radius: 18px 0 0 18px; padding: 20px 24px 32px; box-shadow: -8px 0 30px rgba(0,0,0,.15); }
  #sheet .grab { display: none; }

  /* wider pages: two columns where it helps */
  .list-grid { display: grid; grid-template-columns: minmax(0, 1.2fr) minmax(0, 1fr); gap: 24px; align-items: start; }
  .list-grid > div + div { margin-top: 0; position: sticky; top: 88px; }
  .kpis { gap: 16px; }
  .kpi { padding: 16px; } .kpi .v { font-size: 26px; }
  .bars { height: 180px; }
  .minimap { height: 300px; } .trackmap { height: 380px; }

  /* login / signup / pending screens */
  #app:not(:has(> nav.tabs)) { max-width: 520px; padding-top: 40px; }
  .role-grid { grid-template-columns: repeat(4, 1fr); }
  #app:not(:has(> nav.tabs)) .role-grid { grid-template-columns: 1fr 1fr; }
  #toast { top: 24px; }
}
@media (min-width: 1280px) {
  #bigmap { left: 400px; } .map-list { width: 400px; } .map-tools { left: 412px; } .map-btns { left: 416px; }
}
.sheet-x { display: none; }
@media (min-width: 960px) {
  .sheet-x { display: block; position: sticky; top: 0; float: right; margin: -4px -8px 0 8px; z-index: 2; width: 36px; height: 36px; border: 0; border-radius: 50%; background: #e7e4da; font-size: 16px; cursor: pointer; }
}

/* photos */
.thumb { flex: none; width: 52px; height: 52px; border-radius: 10px; object-fit: cover; background: #eceae4; }
.thumb.big { display: block; width: 120px; height: 120px; margin-bottom: 6px; }
.thumb.empty { display: grid; place-items: center; font-size: 20px; opacity: .5; }
.shop-photo { display: block; width: 100%; max-height: 200px; object-fit: cover; border-radius: 12px; margin-bottom: 10px; }
details summary { cursor: pointer; }

/* v12: ads strip + sold-out items */
.ad-wrap:empty { display: none; }
.ad-wrap { margin-top: 8px; }
.ad-strip { display: flex; align-items: center; gap: 10px; background: var(--card); border-radius: 12px; box-shadow: var(--shadow);
  padding: 8px 10px; cursor: pointer; border-left: 4px solid #e0a100; }
.ad-strip img { width: 44px; height: 44px; object-fit: cover; border-radius: 8px; flex: none; }
.ad-strip .ad-ic { font-size: 26px; }
.ad-strip b { display: block; font-size: 14px; line-height: 1.25; }
.ad-strip span { font-size: 12px; color: var(--muted); display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.ad-strip .grow { min-width: 0; }
.ad-strip .ad-tag { font-size: 10px; background: #fff3cd; color: #7a5a00; border-radius: 6px; padding: 2px 6px; flex: none; display: inline; }
.ad-strip .ad-x { border: 0; background: none; color: var(--muted); font-size: 16px; padding: 4px; flex: none; }
.prod.soldout > .grow, .prod.soldout > .thumb { opacity: .55; }

/* v15: logs */
.log-g { cursor: pointer; }
.log-g.off { opacity: .55; }
.log-pre { background: var(--bg, #f6f6f2); border-radius: 8px; padding: 8px; font-size: 11px; white-space: pre-wrap; word-break: break-word; max-height: 220px; overflow: auto; margin: 0; }
