/* ══════════════════════════════════════════
   地圖頁面樣式
   ══════════════════════════════════════════ */

body.map-body {
  overflow: hidden;
  height: 100dvh;
}

/* ── 全螢幕地圖 ── */
#mapContainer {
  position: fixed;
  inset: 0;
  bottom: 0;
  z-index: 0;
}

/* ── 頂部控制列 ── */
.map-top-bar {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  z-index: 400;
  padding: 12px 16px 8px;
  background: linear-gradient(to bottom, rgba(242,237,232,0.97) 70%, transparent);
  pointer-events: none;
}
.map-top-inner { pointer-events: all; }

.map-top-row {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 8px;
}

.map-back-btn {
  flex-shrink: 0;
  width: 34px;
  height: 34px;
  border-radius: 50%;
  border: none;
  background: var(--c-bg-elevated);
  color: var(--c-text-sub);
  font-size: 18px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: var(--shadow-sm);
  line-height: 1;
}
.map-back-btn:hover { background: var(--c-bg-input); }

.map-trip-select {
  width: 100%;
  padding: 10px 14px;
  border-radius: var(--radius-md);
  border: 1.5px solid var(--c-border);
  background: var(--c-bg-elevated);
  font-family: var(--font-sans);
  font-size: 14px;
  color: var(--c-text);
  appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8' viewBox='0 0 12 8'%3E%3Cpath d='M1 1l5 5 5-5' stroke='%238A8078' stroke-width='1.5' fill='none' stroke-linecap='round'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 12px center;
  box-shadow: var(--shadow-sm);
  cursor: pointer;
}
.map-trip-select:focus { outline: none; border-color: var(--c-green); }

/* 天數 tabs */
.map-day-tabs {
  display: flex;
  gap: 6px;
  overflow-x: auto;
  scrollbar-width: none;
  padding-bottom: 2px;
}
.map-day-tabs::-webkit-scrollbar { display: none; }
.map-day-tab {
  flex-shrink: 0;
  padding: 6px 14px;
  border-radius: 99px;
  border: none;
  background: var(--c-bg-elevated);
  font-family: var(--font-sans);
  font-size: 12px;
  color: var(--c-text-sub);
  cursor: pointer;
  box-shadow: var(--shadow-sm);
  transition: background 0.15s, color 0.15s;
}
.map-day-tab.active {
  background: var(--c-green);
  color: #fff;
}

/* ── 底部抽屜 ── */
.map-sheet {
  position: fixed;
  left: 0;
  right: 0;
  top: var(--map-sheet-min-y, 112px);  /* JS 量完頂部 bar 後寫入，最高只到 top-bar 下方 */
  bottom: 0;                            /* 延伸到視窗底部；bottom-nav 覆蓋在上方 */
  /* height 由 top+bottom 自動決定，不需 dvh */
  background: var(--c-bg-elevated);
  border-radius: 20px 20px 0 0;
  box-shadow: 0 -4px 24px rgba(74,69,64,0.12);
  z-index: 150;   /* 低於 bottom-nav(200)，nav 蓋在 sheet 上 */
  display: flex;
  flex-direction: column;
  /* collapsed：只在 bottom-nav 上方露出 56px 把手 */
  transform: translateY(calc(100% - var(--nav-h, 64px) - 56px));
  transition: transform 0.38s cubic-bezier(0.32,0.72,0,1);
  touch-action: none;
}
.map-sheet.state-half { transform: translateY(50%); }
.map-sheet.state-full { transform: translateY(0); }

/* 拖曳把手 */
.map-sheet-handle {
  flex-shrink: 0;
  padding: 12px 0 8px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  cursor: grab;
  user-select: none;
}
.map-sheet-handle:active { cursor: grabbing; }
.map-sheet-grip {
  width: 36px;
  height: 4px;
  background: var(--c-border);
  border-radius: 99px;
}
.map-sheet-label {
  font-size: 12px;
  color: var(--c-text-hint);
}

/* 抽屜內容 */
.map-sheet-body {
  flex: 1;
  overflow-y: auto;
  padding: 0 16px calc(var(--nav-h, 64px) + 16px);
  -webkit-overflow-scrolling: touch;
}

/* ── 行程卡片 ── */
.map-stop-item {
  display: flex;
  gap: 12px;
  align-items: flex-start;
  padding: 12px 0;
  border-bottom: 1px solid var(--c-border-soft);
  cursor: pointer;
  transition: background 0.1s;
}
.map-stop-item:last-child { border-bottom: none; }
.map-stop-item { transition: background 0.2s; }
.map-stop-item.highlighted { background: var(--c-green-pale); border-radius: var(--radius-md); padding: 12px 8px; margin: 0 -8px; }

.map-stop-num {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 12px;
  font-weight: 600;
  color: #fff;
  flex-shrink: 0;
  margin-top: 2px;
}
.map-stop-content { flex: 1; min-width: 0; }
.map-stop-name { font-size: 14px; color: var(--c-text); font-weight: 500; display: flex; align-items: center; gap: 4px; }
.map-stop-meta { font-size: 12px; color: var(--c-text-hint); margin-top: 3px; display: flex; gap: 8px; flex-wrap: wrap; }
.map-stop-note { font-size: 12px; color: var(--c-text-sub); margin-top: 4px; }

.map-stop-nav {
  flex-shrink: 0;
  align-self: center;
  padding: 5px 10px;
  border-radius: 99px;
  background: var(--c-green-pale);
  color: var(--c-green);
  font-size: 12px;
  font-weight: 500;
  text-decoration: none;
  white-space: nowrap;
  transition: background 0.15s;
}
.map-stop-nav:hover { background: var(--c-green-light); color: #fff; }

/* 交通資訊 */
.map-transport-row {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 6px 0 6px 14px;
  font-size: 11px;
  color: var(--c-text-hint);
}
.map-transport-line {
  width: 1px;
  height: 20px;
  background: var(--c-border);
  margin-left: 13px;
}

/* ── 空狀態 ── */
.map-empty {
  text-align: center;
  padding: 40px 20px;
  color: var(--c-text-hint);
}
.map-empty-icon { display: flex; justify-content: center; color: var(--c-text-hint); margin-bottom: 10px; }
.map-empty-text { font-size: 14px; color: var(--c-text-sub); }

/* ── Popup ── */
.map-popup .leaflet-popup-content-wrapper {
  border-radius: 12px;
  box-shadow: var(--shadow-md);
  padding: 12px 12px 12px;
  background: var(--c-bg-elevated);
}
.map-popup .leaflet-popup-content { margin: 0; min-width: 160px; }
.map-popup .leaflet-popup-tip { background: var(--c-bg-elevated); }
/* 隱藏 Leaflet 原生 × 按鈕，改用自訂的 mp-close */
.map-popup .leaflet-popup-close-button { display: none !important; }
.mp-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 4px;
}
.mp-close {
  flex-shrink: 0;
  width: 20px;
  height: 20px;
  display: flex;
  align-items: center;
  justify-content: center;
  border: none;
  background: none;
  color: var(--c-text-hint);
  font-size: 16px;
  line-height: 1;
  cursor: pointer;
  border-radius: 4px;
  padding: 0;
}
.mp-name { font-size: 14px; font-weight: 500; color: var(--c-text); margin-bottom: 4px; display: flex; align-items: center; gap: 4px; }
.mp-meta { font-size: 12px; color: var(--c-text-hint); margin-bottom: 8px; }
.mp-nav {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 4px 12px;
  border-radius: 99px;
  background: var(--c-green-pale);
  color: var(--c-green);
  font-size: 12px;
  font-weight: 500;
  text-decoration: none;
}
.mp-nav:hover { background: var(--c-green); color: #fff; }

/* ── Leaflet 標記覆寫 ── */
.map-marker-pin {
  width: 28px;
  height: 28px;
  border-radius: 50% 50% 50% 0;
  transform: rotate(-45deg);
  border: 2px solid #fff;
  box-shadow: 0 2px 6px rgba(0,0,0,0.25);
  display: flex;
  align-items: center;
  justify-content: center;
}
.map-marker-num {
  transform: rotate(45deg);
  font-size: 11px;
  font-weight: 700;
  color: #fff;
  line-height: 1;
}

/* ── 景點拖拉排序 ── */
.map-stop-drag-src {
  opacity: 0.28;
  transition: opacity 0.15s;
}

.map-stop-drop-indicator {
  height: 3px;
  background: var(--c-green, #8B9E8A);
  border-radius: 99px;
  margin: 4px 8px;
  box-shadow: 0 0 6px var(--c-green, #8B9E8A);
  animation: mapDropIndicatorPulse 0.8s ease infinite alternate;
}

@keyframes mapDropIndicatorPulse {
  from { opacity: 0.6; }
  to   { opacity: 1; }
}

/* ── 景點拖拉把手 ── */
.map-stop-drag-handle {
  font-size: 16px;
  color: var(--c-text-hint, #aaa);
  cursor: grab;
  padding: 4px 6px 4px 0;
  line-height: 1;
  touch-action: none;
  user-select: none;
  opacity: 0.5;
  flex-shrink: 0;
  transition: opacity 0.15s;
}
.map-stop-drag-handle:active { cursor: grabbing; opacity: 1; }
.map-stop-item { display: flex; align-items: center; }
