:root {
  --primary: #1F7A5A;
  --primary-dark: #145C43;
  --accent: #C0392B;
  --text: #1F2933;
  --muted: #7B8794;
  --line: #E4E7EB;
  --bg: #FFFFFF;
  --shadow: 0 6px 24px rgba(31, 41, 51, .16);
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

html, body {
  margin: 0; padding: 0; height: 100%; overflow: hidden;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Noto Sans TC",
               "PingFang TC", "Microsoft JhengHei", sans-serif;
  color: var(--text); background: #EEF3EE;
}

#map { position: absolute; inset: 0; }

/* ── 頂部搜尋 ─────────────────────────────────────────── */
.top-bar {
  position: absolute; top: calc(10px + var(--safe-top)); left: 10px; right: 10px;
  z-index: 10;
}

.search-wrap {
  display: flex; align-items: center; gap: 8px;
  background: var(--bg); border-radius: 12px; box-shadow: var(--shadow);
  padding: 0 12px; height: 46px;
}

.search-icon { font-size: 15px; opacity: .6; }

#search {
  flex: 1; border: 0; outline: 0; font-size: 16px; /* 16px 以下 iOS 會自動放大頁面 */
  background: transparent; color: var(--text); min-width: 0;
}

.icon-btn {
  border: 0; background: transparent; color: var(--muted);
  font-size: 15px; cursor: pointer; padding: 6px; line-height: 1;
}

.results {
  margin-top: 8px; background: var(--bg); border-radius: 12px;
  box-shadow: var(--shadow); max-height: 46vh; overflow-y: auto;
  -webkit-overflow-scrolling: touch;
}

.result-item {
  display: flex; align-items: center; gap: 10px;
  padding: 11px 14px; border-bottom: 1px solid var(--line); cursor: pointer;
}
.result-item:last-child { border-bottom: 0; }
.result-item:active { background: #F4F7F5; }
.result-kind {
  font-size: 10px; padding: 2px 7px; border-radius: 99px;
  background: #E8F3EE; color: var(--primary-dark); white-space: nowrap; flex-shrink: 0;
}
.result-text { min-width: 0; flex: 1; }
.result-name { font-size: 14px; font-weight: 600; }
.result-sub { font-size: 12px; color: var(--muted); margin-top: 2px; }
.result-empty { padding: 16px; text-align: center; color: var(--muted); font-size: 13px; }

/* ── 設施快捷 ─────────────────────────────────────────── */
.chips {
  position: absolute; top: calc(66px + var(--safe-top)); left: 0; right: 0;
  z-index: 9; display: flex; gap: 7px; padding: 0 10px;
  overflow-x: auto; scrollbar-width: none; -webkit-overflow-scrolling: touch;
}
.chips::-webkit-scrollbar { display: none; }

.chip {
  flex-shrink: 0; border: 0; border-radius: 99px; padding: 7px 13px;
  background: rgba(255, 255, 255, .95); box-shadow: 0 2px 8px rgba(31, 41, 51, .12);
  font-size: 13px; color: var(--text); cursor: pointer; white-space: nowrap;
}
.chip.active { background: var(--primary); color: #fff; }

/* ── 右側工具 ─────────────────────────────────────────── */
.tools {
  position: absolute; right: 10px; bottom: calc(24px + var(--safe-bottom));
  z-index: 9; display: flex; flex-direction: column; gap: 8px;
}
.tool-btn {
  width: 44px; height: 44px; border: 0; border-radius: 12px;
  background: var(--bg); box-shadow: var(--shadow); font-size: 19px; cursor: pointer;
}
.tool-btn.active { background: var(--primary); }

/* ── 底部詳情 ─────────────────────────────────────────── */
.sheet {
  position: absolute; left: 0; right: 0; bottom: 0; z-index: 12;
  background: var(--bg); border-radius: 18px 18px 0 0;
  box-shadow: 0 -6px 28px rgba(31, 41, 51, .2);
  padding: 8px 16px calc(16px + var(--safe-bottom));
  max-height: 62vh; overflow-y: auto; -webkit-overflow-scrolling: touch;
  animation: slide-up .22s ease-out;
}
@keyframes slide-up { from { transform: translateY(100%); } to { transform: translateY(0); } }

.sheet-handle {
  width: 38px; height: 4px; border-radius: 99px; background: var(--line);
  margin: 4px auto 12px;
}
.sheet-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; }
.sheet-head h2 { margin: 0; font-size: 18px; }
.muted { color: var(--muted); font-size: 13px; margin: 4px 0 0; }

.sheet-body { margin-top: 12px; }
.row { display: flex; gap: 10px; padding: 7px 0; border-bottom: 1px solid var(--line); font-size: 14px; }
.row:last-child { border-bottom: 0; }
.row .k { color: var(--muted); flex: 0 0 76px; font-size: 13px; }
.row .v { flex: 1; word-break: break-word; }

.warn {
  background: #FFF7E6; color: #B7791F; font-size: 12px;
  padding: 9px 11px; border-radius: 8px; margin-top: 10px; line-height: 1.5;
}

.dept-list { margin-top: 10px; }
.dept-item {
  display: flex; justify-content: space-between; gap: 10px;
  padding: 8px 0; border-bottom: 1px dashed var(--line); font-size: 13px;
}
.dept-item:last-child { border-bottom: 0; }
.dept-item .floor { color: var(--muted); flex-shrink: 0; }

.sheet-actions { display: flex; gap: 8px; margin-top: 14px; }
.btn {
  flex: 1; border: 0; border-radius: 10px; padding: 12px; font-size: 15px;
  cursor: pointer; font-weight: 600;
}
.btn.primary { background: var(--primary); color: #fff; }
.btn.ghost { background: #F1F4F2; color: var(--text); }
.btn:disabled { opacity: .5; }

/* ── 標記 ─────────────────────────────────────────────── */
.dest-marker {
  width: 22px; height: 22px; border-radius: 50%;
  background: var(--accent); border: 3px solid #fff;
  box-shadow: 0 2px 8px rgba(0, 0, 0, .35);
  position: relative; cursor: pointer;
}
.dest-marker::after {
  content: ''; position: absolute; inset: -9px; border-radius: 50%;
  border: 2px solid var(--accent); opacity: .85;
  animation: pulse 1.8s ease-out infinite;
}
@keyframes pulse {
  0%   { transform: scale(.6); opacity: .9; }
  100% { transform: scale(2.1); opacity: 0; }
}

.me-marker {
  width: 16px; height: 16px; border-radius: 50%;
  background: #2D7FF9; border: 3px solid #fff;
  box-shadow: 0 2px 6px rgba(0, 0, 0, .3);
}

.poi-marker {
  width: 26px; height: 26px; border-radius: 50%;
  background: #fff; border: 2px solid var(--primary);
  display: grid; place-items: center; font-size: 13px;
  box-shadow: 0 2px 6px rgba(0, 0, 0, .2); cursor: pointer;
}

.maplibregl-popup-content {
  border-radius: 10px; padding: 9px 12px; font-size: 13px;
  font-family: inherit; box-shadow: var(--shadow);
}

/* ── Toast / Boot ─────────────────────────────────────── */
.toast {
  position: absolute; left: 50%; bottom: calc(90px + var(--safe-bottom));
  transform: translateX(-50%); z-index: 20;
  background: rgba(31, 41, 51, .92); color: #fff;
  padding: 10px 16px; border-radius: 99px; font-size: 13px;
  max-width: 82vw; text-align: center;
}

.boot {
  position: absolute; inset: 0; z-index: 30;
  background: #EEF3EE; display: grid; place-content: center; justify-items: center; gap: 14px;
  color: var(--muted); font-size: 14px;
}
.spinner {
  width: 30px; height: 30px; border-radius: 50%;
  border: 3px solid var(--line); border-top-color: var(--primary);
  animation: spin .8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
.boot p { margin: 0; }
