:root {
  color-scheme: light;
  --bg: #f6f4f1;          /* 頁面底色 */
  --card: #ffffff;        /* 卡片、浮動元件 */
  --surface: #ffffff;     /* 輸入框 */
  --ink: #1f1b18;         /* 主要文字 */
  --muted: #7c7069;       /* 次要文字 */
  --line: #ece6e0;        /* 分隔線 */
  --accent: #e4572e;      /* 主色（番茄紅） */
  --on-accent: #ffffff;
  --accent-soft: #fde8df;
  --chip: #f3eee9;
  --shadow: 0 2px 6px rgba(60, 40, 30, .12), 0 6px 20px rgba(60, 40, 30, .10);
  --backdrop: rgba(0, 0, 0, .4);
  --warn: #a8690f;
  --warn-soft: #fdf3dc;
  --ok: #2f855a;
  --ok-soft: #e3f4ea;
  --danger: #c53030;
  --radius: 16px;
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-t: env(safe-area-inset-top, 0px);
}
@media (prefers-color-scheme: dark) {
  :root {
    color-scheme: dark;
    --bg: #141110;
    --card: #221d1a;
    --surface: #2b2421;
    --ink: #f3ece6;
    --muted: #a39589;
    --line: #3a302a;
    --accent: #ff7a50;
    --on-accent: #1b1210;
    --accent-soft: #3d241b;
    --chip: #322925;
    --shadow: 0 2px 10px rgba(0, 0, 0, .5);
    --backdrop: rgba(0, 0, 0, .6);
    --warn: #f0b75a;
    --warn-soft: #3a2e17;
    --ok: #68d391;
    --ok-soft: #1c3326;
    --danger: #fc8181;
  }
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
[hidden] { display: none !important; }
html, body { margin: 0; height: 100%; }
body {
  font-family: -apple-system, BlinkMacSystemFont, "PingFang TC", "Noto Sans TC", "Microsoft JhengHei", sans-serif;
  background: var(--bg); color: var(--ink); font-size: 16px; line-height: 1.5;
  position: fixed; inset: 0; overflow: hidden;
}
/* iOS 26 主畫面 App 底部會浮起來（WebKit bug 301108），讓頁面至少跟螢幕一樣高 */
@media (display-mode: standalone) {
  html { min-height: min(100lvh, calc(100% + env(safe-area-inset-top))); }
}
button, input, select, textarea { font: inherit; color: inherit; }
a { color: inherit; }

/* ===== 主畫面 ===== */
#home { position: absolute; inset: 0; overflow: hidden; }
#map { position: absolute; inset: 0; background: #e9e5df; }
.map-msg { position: absolute; left: 50%; top: 45%; transform: translate(-50%, -50%); background: var(--card); padding: 12px 16px; border-radius: 12px; box-shadow: var(--shadow); font-size: 14px; text-align: center; z-index: 2; }
.maplibregl-ctrl-attrib { font-size: 10px; }
.maplibregl-ctrl-bottom-right, .maplibregl-ctrl-bottom-left { display: none; }

/* 浮在地圖上的搜尋列 */
.top { position: absolute; left: 0; right: 0; top: 0; z-index: 6; padding: calc(var(--safe-t) + 10px) 12px 0; pointer-events: none; }
.top > * { pointer-events: auto; }
.searchbar {
  display: flex; align-items: center; gap: 4px; background: var(--card); border-radius: 26px; box-shadow: var(--shadow);
  height: 50px; padding: 0 6px 0 16px;
}
.s-icon { font-size: 17px; opacity: .7; }
.searchbar input { flex: 1; min-width: 0; border: 0; outline: 0; background: none; font-size: 17px; padding: 0 6px; height: 100%; }
.searchbar input::-webkit-search-cancel-button { display: none; }
.s-clear { border: 0; background: var(--chip); color: var(--muted); width: 24px; height: 24px; border-radius: 50%; font-size: 12px; padding: 0; cursor: pointer; flex: none; }
.s-btn { border: 0; background: none; width: 40px; height: 40px; border-radius: 50%; font-size: 19px; cursor: pointer; flex: none; color: var(--ink); }
.s-btn:active { background: var(--chip); }
.chips { display: flex; gap: 8px; overflow-x: auto; padding: 10px 12px 6px; margin: 0 -12px; scrollbar-width: none; }
.chips::-webkit-scrollbar { display: none; }
.chip {
  flex: none; border: 0; border-radius: 99px; padding: 7px 13px; font-size: 14px; background: var(--card); color: var(--ink);
  box-shadow: 0 1px 4px rgba(60, 40, 30, .18); cursor: pointer; white-space: nowrap;
}
.chip small { color: var(--muted); margin-left: 3px; font-size: 12px; }
.chip.on { background: var(--accent); color: var(--on-accent); font-weight: 600; }
.chip.on small { color: inherit; opacity: .85; }

/* 圖釘 */
.pin { position: relative; cursor: pointer; display: flex; flex-direction: column; align-items: center; }
.pin .bub {
  width: 38px; height: 38px; border-radius: 50%; background: #fff; border: 2.5px solid var(--accent);
  display: grid; place-items: center; font-size: 20px; line-height: 1; box-shadow: 0 2px 6px rgba(0,0,0,.25);
}
.pin .tail { width: 0; height: 0; border-left: 6px solid transparent; border-right: 6px solid transparent; border-top: 8px solid var(--accent); margin-top: -1px; }
.pin.approx .bub { border-style: dashed; }
.pin .lbl {
  position: absolute; top: 100%; left: 50%; transform: translateX(-50%); margin-top: 1px;
  font-size: 12px; font-weight: 700; color: #3a2a22; white-space: nowrap; max-width: 130px; overflow: hidden; text-overflow: ellipsis;
  text-shadow: 0 0 3px #fff, 0 0 3px #fff, 0 0 3px #fff, 0 0 3px #fff; pointer-events: none;
}
.pin.sel { z-index: 3; }
.pin.sel .bub { background: var(--accent); width: 48px; height: 48px; font-size: 25px; border-color: #fff; }
.cluster {
  min-width: 40px; height: 40px; padding: 0 8px; border-radius: 20px; background: var(--accent); color: #fff; font-weight: 800; font-size: 15px;
  display: grid; place-items: center; border: 3px solid #fff; box-shadow: 0 2px 8px rgba(0,0,0,.3); cursor: pointer;
}
.me-dot { width: 18px; height: 18px; border-radius: 50%; background: #1a73e8; border: 3px solid #fff; box-shadow: 0 0 0 6px rgba(26, 115, 232, .2); }

.fab {
  position: absolute; right: 12px; z-index: 3; width: 46px; height: 46px; border-radius: 50%; border: 0; background: var(--card);
  box-shadow: var(--shadow); font-size: 18px; cursor: pointer; color: #1a73e8;
}
.fab.locate { transform: rotate(-45deg); }

/* 底部抽屜 */
.drawer {
  position: absolute; left: 0; right: 0; bottom: 0; z-index: 5; background: var(--card); border-radius: 20px 20px 0 0;
  box-shadow: 0 -2px 16px rgba(60, 40, 30, .16); display: flex; flex-direction: column; will-change: transform;
}
.drawer.anim { transition: transform .28s cubic-bezier(.2, .8, .2, 1); }
.grab { padding: 8px 0 4px; display: flex; justify-content: center; cursor: grab; touch-action: none; }
.grab i { width: 38px; height: 5px; border-radius: 3px; background: var(--line); }
.d-head { padding: 0 16px 8px; touch-action: none; display: flex; align-items: center; gap: 10px; }
.d-head .ttl { flex: 1; min-width: 0; font-size: 17px; font-weight: 800; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.d-head .ttl small { font-weight: 500; color: var(--muted); font-size: 13px; margin-left: 4px; }
.d-head .add { border: 0; background: var(--accent-soft); color: var(--accent); font-weight: 700; border-radius: 99px; padding: 6px 12px; font-size: 14px; cursor: pointer; flex: none; }
.d-head .x { border: 0; background: var(--chip); width: 32px; height: 32px; border-radius: 50%; font-size: 14px; cursor: pointer; flex: none; color: var(--muted); }
.d-body { flex: 1; overflow-y: auto; -webkit-overflow-scrolling: touch; overscroll-behavior: contain; padding: 0 14px calc(16px + var(--safe-b)); }

/* 清單模式：抽屜變整頁，地圖藏起來 */
#home.list-mode #map, #home.list-mode .fab, #home.list-mode .map-msg { visibility: hidden; }
#home.list-mode { background: var(--bg); }
#home.list-mode .drawer { transform: none !important; border-radius: 0; box-shadow: none; background: var(--bg); }
#home.list-mode .grab { display: none; }
#home.list-mode .chip { box-shadow: none; background: var(--chip); }
#home.list-mode .chip.on { background: var(--accent); }

/* 電腦版：左邊清單、右邊地圖 */
@media (min-width: 900px) {
  .top { width: 420px; padding-left: 16px; padding-right: 16px; }
  .chips { margin: 0 -16px; padding-left: 16px; padding-right: 16px; }
  .drawer { right: auto; width: 420px; top: 0; border-radius: 0; transform: none !important; box-shadow: 2px 0 12px rgba(60, 40, 30, .12); }
  .grab { display: none; }
  #home.list-mode #map, #home.list-mode .fab { visibility: visible; }
  #home.list-mode .drawer { background: var(--card); box-shadow: 2px 0 12px rgba(60, 40, 30, .12); }
  #modeBtn { display: none; }
}

/* 店家卡片 */
.group-title { font-size: 13px; font-weight: 700; color: var(--muted); margin: 14px 4px 8px; }
.group-title b { color: var(--ink); font-size: 15px; margin-right: 4px; }
.card {
  display: flex; gap: 12px; align-items: flex-start; background: var(--card); border-radius: var(--radius); padding: 12px;
  margin-bottom: 8px; border: 1px solid var(--line); cursor: pointer;
}
#home.list-mode .card { border: 0; box-shadow: 0 2px 10px rgba(60, 40, 30, .07); }
.card:active { transform: scale(.99); }
.emoji { flex: none; width: 46px; height: 46px; border-radius: 14px; background: var(--accent-soft); display: grid; place-items: center; font-size: 25px; }
.card .body { flex: 1; min-width: 0; }
.card h3 { margin: 0; font-size: 16px; font-weight: 700; line-height: 1.35; word-break: break-word; }
.meta { display: flex; flex-wrap: wrap; align-items: center; gap: 4px 6px; margin-top: 4px; font-size: 13px; color: var(--muted); }
.tag { background: var(--chip); color: var(--ink); border-radius: 6px; padding: 0 7px; font-size: 12px; line-height: 20px; }
.badge { border-radius: 6px; padding: 0 7px; font-size: 12px; line-height: 20px; font-weight: 600; }
.badge.ok { background: var(--ok-soft); color: var(--ok); }
.badge.warn { background: var(--warn-soft); color: var(--warn); }
.line { font-size: 13.5px; margin-top: 5px; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.line.muted { color: var(--muted); }
.empty { text-align: center; color: var(--muted); padding: 36px 10px; }
.empty .big { font-size: 42px; }

/* 點圖釘後的店家小卡 */
.place .p-name { font-size: 21px; font-weight: 800; margin: 0; line-height: 1.3; }
.place .meta { font-size: 14px; margin-top: 6px; }
.place .info { margin-top: 10px; font-size: 14.5px; }
.place .info div { display: flex; gap: 8px; margin-top: 6px; }
.place .info div > span:first-child { flex: none; }
.actions { display: flex; gap: 8px; margin-top: 14px; overflow-x: auto; scrollbar-width: none; }
.actions::-webkit-scrollbar { display: none; }
.act {
  flex: none; display: inline-flex; align-items: center; gap: 6px; border: 1px solid var(--line); background: var(--card); color: var(--ink);
  border-radius: 99px; padding: 8px 14px; font-size: 14px; font-weight: 600; text-decoration: none; cursor: pointer;
}
.act.primary { background: var(--accent); border-color: var(--accent); color: var(--on-accent); }

/* 放圖釘模式 */
.pick { position: absolute; inset: 0; z-index: 8; pointer-events: none; }
.pick > * { pointer-events: auto; }
.pick-top { position: absolute; left: 12px; right: 12px; top: calc(var(--safe-t) + 10px); background: var(--card); border-radius: 14px; box-shadow: var(--shadow); padding: 12px 14px; font-size: 14.5px; }
.pick-top b { display: block; font-size: 16px; }
.pick-pin { position: absolute; left: 50%; top: 50%; transform: translate(-50%, -100%); font-size: 44px; pointer-events: none; filter: drop-shadow(0 3px 3px rgba(0,0,0,.3)); }
.pick-bar { position: absolute; left: 12px; right: 12px; bottom: calc(var(--safe-b) + 16px); display: flex; gap: 10px; }
.pick-bar .btn { flex: 1; box-shadow: var(--shadow); }
#home.picking .top, #home.picking .drawer, #home.picking .fab { display: none; }

/* ===== 整頁（店家資料、新增、設定） ===== */
#page { position: absolute; inset: 0; z-index: 10; background: var(--bg); display: flex; flex-direction: column; }
.topbar { display: flex; align-items: center; gap: 8px; padding: calc(var(--safe-t) + 10px) 16px 10px; background: var(--bg); }
.topbar h1 { flex: 1; margin: 0; font-size: 18px; font-weight: 700; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.back-btn { border: 0; background: none; color: var(--accent); font-size: 17px; padding: 4px 6px 4px 0; display: flex; align-items: center; gap: 2px; cursor: pointer; }
.back-btn span { font-size: 28px; line-height: 1; margin-top: -3px; }
.sync { border: 0; border-radius: 99px; padding: 3px 10px; font-size: 12px; background: var(--chip); color: var(--muted); cursor: pointer; }
.sync.ok { background: var(--ok-soft); color: var(--ok); }
.sync.busy { background: var(--accent-soft); color: var(--accent); }
.sync.err { background: var(--warn-soft); color: var(--warn); }
.scroller { flex: 1; min-height: 0; overflow-y: auto; -webkit-overflow-scrolling: touch; overscroll-behavior-y: contain; }
main { max-width: 640px; margin: 0 auto; padding: 0 16px calc(28px + var(--safe-b)); }

.panel { background: var(--card); border-radius: var(--radius); padding: 16px; margin: 12px 0; box-shadow: 0 2px 10px rgba(60, 40, 30, .07); }
.panel h2 { margin: 0 0 6px; font-size: 17px; }
.field { display: block; margin-top: 12px; }
.field > span { display: block; font-size: 13px; color: var(--muted); margin-bottom: 4px; font-weight: 600; }
.field input, .field select, .field textarea {
  width: 100%; border: 1.5px solid var(--line); background: var(--surface); border-radius: 12px; padding: 10px 12px; font-size: 16px; outline: 0;
}
.field input:focus, .field select:focus, .field textarea:focus { border-color: var(--accent); }
.field textarea { min-height: 84px; resize: vertical; }
.row { display: flex; gap: 10px; }
.row > * { flex: 1; min-width: 0; }
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px; border: 0; border-radius: 12px; padding: 12px 16px;
  background: var(--accent); color: var(--on-accent); font-weight: 700; font-size: 16px; cursor: pointer; text-decoration: none;
}
.btn.line-btn { background: var(--chip); color: var(--ink); }
.pick-bar .btn.line-btn { background: var(--card); }
.btn.ghost { background: none; color: var(--muted); }
.btn.danger { background: none; color: var(--danger); }
.btn.block { display: flex; width: 100%; }
.btn:disabled { opacity: .5; }
.small { font-size: 13px; color: var(--muted); }
.notice { border-radius: 12px; padding: 10px 12px; font-size: 14px; margin-top: 12px; }
.notice.warn { background: var(--warn-soft); color: var(--warn); }
.notice.ok { background: var(--ok-soft); color: var(--ok); }
.notice .btn { padding: 6px 12px; font-size: 14px; margin-top: 8px; }
.detail-head { display: flex; gap: 12px; align-items: center; margin-top: 8px; }
.detail-head .emoji { width: 56px; height: 56px; font-size: 30px; border-radius: 16px; }
.detail-head h2 { margin: 0; font-size: 21px; line-height: 1.3; }
.steps { padding-left: 20px; margin: 8px 0; }
.steps li { margin: 4px 0; }
.foot { text-align: center; margin: 24px 0 8px; }

/* 底部彈出視窗、提示 */
.sheet-backdrop { position: fixed; inset: 0; background: var(--backdrop); z-index: 20; }
.sheet {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 21; background: var(--card); border-radius: 20px 20px 0 0;
  padding: 20px 18px calc(18px + var(--safe-b)); max-width: 640px; margin: 0 auto; max-height: 85vh; overflow-y: auto;
}
.sheet h2 { margin: 0 0 8px; font-size: 18px; }
.toast {
  position: fixed; left: 50%; transform: translateX(-50%); top: calc(var(--safe-t) + 70px); z-index: 30;
  background: rgba(30, 22, 18, .92); color: #fff; padding: 10px 16px; border-radius: 12px; font-size: 14px; max-width: 86vw; text-align: center;
}

