:root {
  --teal: #0f766e;
  --teal-d: #0b5850;
  --ink: #14201f;
  --muted: #5f6b6a;
  --line: #e4e9e8;
  --bg: #f5f7f6;
  --card: #ffffff;
  --fairprice: #0a8a3f;
  --coldstorage: #c8102e;
  --shengsiong: #f37021;
  --radius: 14px;
  --shadow: 0 1px 3px rgba(20, 32, 31, 0.08), 0 1px 2px rgba(20, 32, 31, 0.04);
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; padding: 0; }
body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--ink);
  line-height: 1.45;
  padding-bottom: env(safe-area-inset-bottom);
}

.app-bar {
  background: linear-gradient(135deg, var(--teal), var(--teal-d));
  color: #fff;
  padding: calc(env(safe-area-inset-top) + 16px) 18px 16px;
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
}
.account { display: flex; align-items: center; }
.header-btn { background: rgba(255,255,255,0.16); color: #fff; padding: 8px 14px; }
.header-btn:hover { background: rgba(255,255,255,0.26); }
.account-user { display: flex; flex-direction: column; align-items: flex-end; gap: 1px; }
#account-name { font-size: 13px; font-weight: 600; max-width: 160px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.linkbtn { background: none; border: none; color: inherit; font: inherit; text-decoration: underline; cursor: pointer; padding: 0; opacity: 0.9; font-size: 12px; }

.overlay {
  position: fixed; inset: 0; background: rgba(15, 32, 31, 0.55); z-index: 50;
  display: flex; align-items: center; justify-content: center; padding: 18px;
}
.login-card {
  background: var(--card); border-radius: 16px; box-shadow: 0 12px 40px rgba(0,0,0,0.3);
  padding: 24px 22px; width: 100%; max-width: 380px; position: relative;
}
.login-close { position: absolute; top: 10px; right: 14px; background: none; border: none; font-size: 24px; color: var(--muted); cursor: pointer; }
.login-brand { font-size: 22px; font-weight: 800; color: var(--teal-d); }
.login-tag { font-size: 13.5px; color: var(--muted); margin: 4px 0 18px; }
.login-card input {
  width: 100%; padding: 12px 14px; font-size: 15px; border: 1px solid var(--line);
  border-radius: 10px; font-family: inherit; margin-bottom: 10px; background: #fbfcfc;
}
.login-card input:focus { outline: 2px solid var(--teal); border-color: var(--teal); }
.google-slot { display: flex; justify-content: center; margin-bottom: 4px; }
.login-or { display: flex; align-items: center; text-align: center; color: var(--muted); font-size: 12px; margin: 12px 0; }
.login-or::before, .login-or::after { content: ""; flex: 1; height: 1px; background: var(--line); }
.login-or span { padding: 0 10px; }
.code-sent { font-size: 13px; color: var(--teal-d); margin: 0 0 10px; font-weight: 600; }
.login-err { color: var(--coldstorage); font-size: 13px; min-height: 18px; margin-top: 6px; }
.login-fine { font-size: 11.5px; color: var(--muted); margin: 12px 0 0; text-align: center; }
.brand-mark { font-size: 22px; font-weight: 800; letter-spacing: -0.3px; }
.brand-na { opacity: 0.85; font-weight: 500; }
.brand-sub { display: block; font-size: 12.5px; opacity: 0.85; margin-top: 2px; }

main { max-width: 620px; margin: 0 auto; padding: 14px 14px 24px; }

.card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 14px;
  margin-bottom: 12px;
}
.card-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 10px; }
.card-head h2 { font-size: 15px; margin: 0; font-weight: 700; }
.pill {
  background: var(--teal); color: #fff; font-size: 12px; font-weight: 700;
  min-width: 22px; height: 22px; border-radius: 11px; display: inline-flex;
  align-items: center; justify-content: center; padding: 0 7px;
}

.loc-row { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.loc-label { font-weight: 600; }

.btn {
  border: none; border-radius: 10px; padding: 10px 14px; font-size: 14px;
  font-weight: 600; cursor: pointer; font-family: inherit;
}
.btn.ghost { background: #eef4f3; color: var(--teal-d); }
.btn.primary { background: var(--teal); color: #fff; }
.btn.primary:disabled { background: #b9cbc8; cursor: not-allowed; }
.btn.block { width: 100%; padding: 14px; font-size: 15.5px; margin: 4px 0 16px; }

.search-wrap { position: relative; }
#search {
  width: 100%; padding: 12px 14px; font-size: 15px; border: 1px solid var(--line);
  border-radius: 10px; font-family: inherit; background: #fbfcfc;
}
#search:focus { outline: 2px solid var(--teal); border-color: var(--teal); }
.results {
  position: absolute; left: 0; right: 0; top: calc(100% + 6px); z-index: 15;
  background: #fff; border: 1px solid var(--line); border-radius: 10px;
  box-shadow: 0 8px 24px rgba(20, 32, 31, 0.14); max-height: 320px; overflow-y: auto;
}
.results.hidden { display: none; }
.result {
  display: flex; align-items: center; gap: 10px;
  padding: 10px 12px; border-bottom: 1px solid var(--line); cursor: pointer;
}
.result:last-child { border-bottom: none; }
.result:active { background: #f2f7f6; }
.result-body { flex: 1; min-width: 0; }
.thumb {
  width: 44px; height: 44px; border-radius: 8px; object-fit: contain;
  background: #fff; border: 1px solid var(--line); flex-shrink: 0;
}
.thumb.sm { width: 34px; height: 34px; border-radius: 6px; }
.result-name { font-size: 13.5px; font-weight: 600; }
.result-meta { font-size: 11.5px; color: var(--muted); }
.chips { display: flex; gap: 4px; flex-shrink: 0; }
.chip {
  font-size: 10.5px; font-weight: 700; color: #fff; border-radius: 6px;
  padding: 2px 6px; white-space: nowrap;
}
.chip.fp { background: var(--fairprice); }
.chip.cs { background: var(--coldstorage); }
.chip.ss { background: var(--shengsiong); }

.basket { list-style: none; margin: 10px 0 0; padding: 0; }
.basket li {
  display: flex; align-items: center; gap: 10px;
  padding: 9px 0; border-bottom: 1px solid var(--line);
}
.basket li:last-child { border-bottom: none; }
.b-body { flex: 1; min-width: 0; }
.b-name { font-size: 13.5px; font-weight: 600; }
.b-meta { font-size: 11.5px; color: var(--muted); }
.b-remove {
  background: none; border: none; color: var(--coldstorage); font-size: 20px;
  cursor: pointer; line-height: 1; padding: 0 4px;
}
.empty { color: var(--muted); font-size: 13px; text-align: center; padding: 8px 0; }
.hidden { display: none; }

.prefs { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.pref { display: flex; flex-direction: column; gap: 6px; font-size: 12.5px; color: var(--muted); font-weight: 600; }
.pref-wide { grid-column: 1 / -1; }
.pref select {
  padding: 9px 10px; border: 1px solid var(--line); border-radius: 9px;
  font-size: 14px; font-family: inherit; background: #fbfcfc; color: var(--ink);
}
.pref b { color: var(--teal-d); }
input[type="range"] { width: 100%; accent-color: var(--teal); }
.range-ends { display: flex; justify-content: space-between; font-size: 11px; color: var(--muted); font-weight: 500; }

/* plan results */
.plan-summary { font-size: 13px; color: var(--muted); margin: 2px 4px 12px; }
.plan-card {
  background: var(--card); border: 1px solid var(--line); border-radius: var(--radius);
  box-shadow: var(--shadow); padding: 14px; margin-bottom: 12px;
}
.plan-card.best { border: 2px solid var(--teal); }
.plan-top { display: flex; align-items: baseline; justify-content: space-between; margin-bottom: 4px; }
.plan-stores { font-size: 15px; font-weight: 800; }
.plan-total { font-size: 18px; font-weight: 800; color: var(--teal-d); }
.plan-meta { font-size: 12px; color: var(--muted); margin-bottom: 10px; }
.badge-best {
  background: var(--teal); color: #fff; font-size: 10.5px; font-weight: 800;
  border-radius: 6px; padding: 2px 7px; margin-left: 8px; vertical-align: middle;
}
.assign { list-style: none; margin: 0; padding: 0; }
.assign li {
  display: flex; align-items: center; gap: 8px;
  padding: 6px 0; border-top: 1px dashed var(--line); font-size: 13px;
}
.assign .a-body { flex: 1; min-width: 0; display: flex; align-items: center; gap: 8px; }
.assign .a-right { display: flex; align-items: center; gap: 8px; flex-shrink: 0; }
.assign .a-price { font-weight: 700; }
.store-tag { font-size: 10.5px; font-weight: 700; color: #fff; border-radius: 6px; padding: 2px 7px; }
.store-tag.fp { background: var(--fairprice); }
.store-tag.cs { background: var(--coldstorage); }
.store-tag.ss { background: var(--shengsiong); }
.missing { color: var(--coldstorage); font-size: 12px; margin-top: 8px; }
.save-note {
  background: #eafaf3; color: #0a6b3f; border: 1px solid #bfe9d3;
  border-radius: 10px; padding: 10px 12px; font-size: 13px; font-weight: 600;
  margin: 2px 4px 14px;
}

.map-wrap { margin: 6px 0 12px; border-radius: var(--radius); overflow: hidden; border: 1px solid var(--line); background: #eef3f2; }
.map-wrap svg { display: block; width: 100%; height: auto; }
.leaflet-map { height: 240px; width: 100%; }
.leaflet-map .pin-label {
  background: #fff; border: 1px solid var(--line); border-radius: 6px;
  padding: 1px 5px; font-size: 11px; font-weight: 700; white-space: nowrap;
  box-shadow: 0 1px 2px rgba(0,0,0,0.15);
}
.leaflet-container { font: inherit; }
.locate-btn {
  display: flex; align-items: center; justify-content: center;
  width: 38px; height: 38px; background: #fff; color: var(--teal-d);
  border-radius: 10px; box-shadow: 0 1px 4px rgba(0,0,0,0.25);
  margin: 10px 10px 0 0; cursor: pointer;
}
.locate-btn:hover { background: #f2f7f6; }
.locate-btn.busy { color: #b9cbc8; }
.locate-btn.busy svg { animation: spin 0.9s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

/* highlighted route: animated flow in the direction of travel */
.route-flow { stroke-dasharray: 1 12; animation: routeflow 1s linear infinite; }
@keyframes routeflow { to { stroke-dashoffset: -13; } }

/* numbered stop markers on the map */
.stop-marker { background: none; border: none; }
.stop-pin {
  width: 26px; height: 26px; border-radius: 50%; color: #fff;
  font-size: 13px; font-weight: 800; display: flex; align-items: center;
  justify-content: center; border: 2px solid #fff; box-shadow: 0 1px 3px rgba(0,0,0,0.4);
}
.stop-pin.you { width: 18px; height: 18px; }
.stop-lbl {
  position: absolute; top: -18px; left: 50%; transform: translateX(-50%);
  background: #fff; border: 1px solid var(--line); border-radius: 5px;
  padding: 0 5px; font-size: 10.5px; font-weight: 700; white-space: nowrap;
  box-shadow: 0 1px 2px rgba(0,0,0,0.15);
}

/* ordered stops strip in the plan card */
.route-strip {
  display: flex; align-items: center; flex-wrap: wrap; gap: 5px;
  margin: 2px 0 10px; font-size: 12px;
}
.route-node { font-weight: 700; color: var(--muted); }
.route-arrow { color: var(--muted); }
.stop-badge {
  font-size: 11px; font-weight: 700; color: #fff; border-radius: 6px; padding: 2px 7px;
}
.stop-badge.fp { background: var(--fairprice); }
.stop-badge.cs { background: var(--coldstorage); }
.stop-badge.ss { background: var(--shengsiong); }

.foot { text-align: center; color: var(--muted); font-size: 11px; padding: 4px 0 18px; }
