:root {
  --bg: #12100f;
  --surface: #1d1a18;
  --surface-2: #262220;
  --line: #332e2b;
  --text: #f5f1ee;
  --muted: #9b918a;
  --accent: #ff7a59;
  --accent-ink: #2a1109;
  --danger: #ff6b6b;
  --radius: 14px;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: system-ui, -apple-system, "Noto Sans TC", "Microsoft JhengHei", sans-serif;
  -webkit-font-smoothing: antialiased;
  overscroll-behavior-y: none;
}

.hidden { display: none !important; }
.muted { color: var(--muted); }
.small { font-size: 12px; line-height: 1.6; }

button {
  font: inherit;
  cursor: pointer;
  border: none;
  border-radius: 10px;
  transition: opacity .15s ease, transform .05s ease;
}
button:active { transform: scale(.98); }
button:disabled { opacity: .5; cursor: default; }

.primary {
  background: var(--accent);
  color: var(--accent-ink);
  font-weight: 700;
  padding: 12px 18px;
}

.send-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0;
  width: 44px;
  height: 44px;
  flex: 0 0 auto;
}

.ghost {
  background: transparent;
  color: var(--muted);
  border: 1px solid var(--line);
  padding: 10px 14px;
}

.icon-btn {
  background: transparent;
  color: var(--muted);
  font-size: 20px;
  width: 38px;
  height: 38px;
  line-height: 1;
}

input, textarea {
  font: inherit;
  width: 100%;
  background: var(--surface-2);
  color: var(--text);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 12px;
  outline: none;
  resize: none;
}
input:focus, textarea:focus { border-color: var(--accent); }

/* ── 首次設定 ─────────────────────────────── */
.setup {
  min-height: 100dvh;
  display: grid;
  place-items: center;
  padding: 24px;
}
.setup-card { width: 100%; max-width: 420px; }
.setup-card h1 { font-size: 22px; margin: 0 0 8px; }
.setup-card p { margin: 0 0 16px; line-height: 1.7; font-size: 14px; }
.setup-card input { margin-bottom: 12px; }
.setup-card .primary { width: 100%; }
code {
  background: var(--surface-2);
  padding: 1px 6px;
  border-radius: 5px;
  font-size: .9em;
}

.error {
  color: var(--danger);
  font-size: 13px;
  margin: 10px 0 0;
  line-height: 1.6;
}

/* ── 主畫面 ───────────────────────────────── */
#app {
  display: flex;
  flex-direction: column;
  height: 100dvh;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: max(10px, env(safe-area-inset-top)) 14px 10px;
  flex: 0 0 auto;
}
.topbar h1 { font-size: 17px; margin: 0; letter-spacing: .02em; }
.topbar-actions { display: flex; align-items: center; gap: 6px; }
.count {
  background: var(--surface-2);
  color: var(--muted);
  font-size: 12px;
  padding: 3px 9px;
  border-radius: 999px;
}

.map {
  flex: 1 1 auto;
  min-height: 180px;
  background: var(--surface);
}

.sheet {
  flex: 0 0 auto;
  max-height: 58dvh;
  overflow-y: auto;
  background: var(--surface);
  border-top: 1px solid var(--line);
  border-radius: 18px 18px 0 0;
  padding: 12px 14px max(14px, env(safe-area-inset-bottom));
}

.input-row {
  display: flex;
  gap: 8px;
  align-items: flex-start;
}
.input-row textarea { max-height: 120px; }

.status {
  margin: 10px 2px 0;
  font-size: 13px;
  color: var(--muted);
  line-height: 1.6;
}
.status.is-error { color: var(--danger); }

/* ── 候選結果 ─────────────────────────────── */
.candidates { margin-top: 12px; }
.candidates-title { font-size: 13px; color: var(--muted); margin: 0 2px 8px; }

.cand {
  width: 100%;
  text-align: left;
  background: var(--surface-2);
  color: var(--text);
  border: 1px solid var(--line);
  padding: 12px;
  margin-bottom: 8px;
  border-radius: var(--radius);
}
.cand-name { font-weight: 700; font-size: 15px; }
.cand-meta { color: var(--muted); font-size: 12.5px; margin-top: 4px; line-height: 1.5; }
.cand.picked { border-color: var(--accent); background: #2a1e18; }
.cand.picked::before { content: '✓ '; color: var(--accent); font-weight: 700; }

.batch-actions {
  display: flex;
  gap: 8px;
  margin-top: 10px;
}
.batch-actions .primary { flex: 1; }

/* ── 已存清單 ─────────────────────────────── */
.list { margin-top: 12px; display: flex; flex-direction: column; gap: 8px; }

.item {
  background: var(--surface-2);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 12px;
}
.item-head {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 10px;
}
.item-name {
  font-weight: 700;
  font-size: 15px;
  background: none;
  border: none;
  color: var(--text);
  padding: 0;
  text-align: left;
  flex: 1;
}
.item-meta { color: var(--muted); font-size: 12.5px; margin-top: 4px; line-height: 1.5; }
.item-actions { display: flex; gap: 6px; flex: 0 0 auto; }
.mini {
  background: transparent;
  border: 1px solid var(--line);
  color: var(--muted);
  font-size: 12px;
  padding: 5px 9px;
}
.mini.danger { color: var(--danger); border-color: #4a2b2b; }

.item.in-plan {
  border-color: var(--accent);
  background: #2a1e18;
}

.plan-bar {
  position: sticky;
  bottom: 0;
  z-index: 5;
  display: flex;
  justify-content: space-between;
  align-items: center;
  background: var(--surface-2);
  border-top: 1px solid var(--line);
  padding: 10px 14px max(10px, env(safe-area-inset-bottom));
  margin: 0 -14px -14px;
}
.plan-bar-actions { display: flex; gap: 8px; }

.empty {
  color: var(--muted);
  font-size: 13.5px;
  text-align: center;
  line-height: 1.9;
  padding: 22px 10px;
  margin: 0;
}

/* ── 設定 ─────────────────────────────────── */
.modal {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, .6);
  display: flex;
  align-items: center;
  justify-content: center;
  /* Leaflet 的 tile/control 用到 400~1000，這裡要蓋過它才不會被地圖擋住 */
  z-index: 10000;
  padding: 20px;
}
.modal-card {
  width: 100%;
  max-width: 520px;
  background: var(--surface);
  border-radius: 18px;
  padding: 20px 20px max(20px, env(safe-area-inset-bottom));
  max-height: calc(100dvh - 40px);
  overflow-y: auto;
  overscroll-behavior: contain;
}

/* 手機由下浮出、貼底更順手 */
@media (max-width: 600px) {
  .modal { align-items: flex-end; padding: 0; }
  .modal-card {
    border-radius: 18px 18px 0 0;
    max-height: 90dvh;
  }
}
.modal-card h2 { margin: 0 0 14px; font-size: 17px; }
.modal-card label {
  display: block;
  font-size: 13px;
  color: var(--muted);
  margin: 12px 0 6px;
}
.modal-actions {
  display: flex;
  gap: 8px;
  justify-content: flex-end;
  margin-top: 18px;
}

/* Google 地圖資訊視窗在深色底下的可讀性 */
.gm-style .gm-style-iw-c { color: #1a1a1a; }
