/* PlanMaps Modern Theme Stylesheet */
:root {
  --primary: #60a5fa;
  --primary-hover: #3b82f6;
  --primary-light: rgba(96, 165, 250, 0.2);
  --success: #10b981;
  --success-light: rgba(16, 185, 129, 0.15);
  --warning: #f59e0b;
  --danger: #ef4444;
  --bg-dark: #0f172a;
  --bg-card: rgba(30, 41, 59, 0.94);
  --bg-surface: #1e293b;
  --bg-surface-hover: #2d3748;
  --bg-input: #334155;
  --text-main: #f8fafc;
  --text-muted: #94a3b8;
  --border: rgba(255, 255, 255, 0.1);
  --shadow-lg: 0 10px 25px -5px rgba(0, 0, 0, 0.5), 0 8px 10px -6px rgba(0, 0, 0, 0.5);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --safe-top: env(safe-area-inset-top, 0px);
}

[data-theme="light"] {
  --primary: #2563eb;
  --primary-hover: #1d4ed8;
  --primary-light: rgba(37, 99, 235, 0.12);
  --success: #059669;
  --success-light: rgba(16, 185, 129, 0.15);
  --warning: #d97706;
  --danger: #dc2626;
  --bg-dark: #f8fafc;
  --bg-card: rgba(255, 255, 255, 0.95);
  --bg-surface: #ffffff;
  --bg-surface-hover: #f1f5f9;
  --bg-input: #f1f5f9;
  --text-main: #0f172a;
  --text-muted: #64748b;
  --border: rgba(0, 0, 0, 0.1);
  --shadow-lg: 0 10px 25px -5px rgba(0, 0, 0, 0.1), 0 8px 10px -6px rgba(0, 0, 0, 0.06);
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  -webkit-tap-highlight-color: transparent;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}

html, body {
  background-color: var(--bg-dark);
  color: var(--text-main);
  height: 100%;
  width: 100%;
  margin: 0;
  padding: 0;
  overflow: hidden;
  position: relative;
  user-select: none;
  -webkit-user-select: none;
  touch-action: pan-x pan-y;
  overscroll-behavior: none;
  -webkit-touch-callout: none;
  transition: background-color 0.3s ease, color 0.3s ease;
}

/* App Container - Pin tightly to full screen */
.app-container {
  position: fixed;
  inset: 0;
  display: flex;
  overflow: hidden;
}

/* Map Canvas */
#map {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  z-index: 1;
  background-color: #e2e8f0;
}

/* Reposition MapLibre navigation controls */
.maplibregl-ctrl-top-right {
  top: max(74px, calc(env(safe-area-inset-top, 0px) + 60px)) !important;
  right: 18px !important;
  z-index: 990 !important;
}

.maplibregl-ctrl-top-right .maplibregl-ctrl {
  margin-right: 0 !important;
  margin-left: 0 !important;
}

.maplibregl-ctrl-group {
  background: var(--bg-surface) !important;
  border: 1px solid var(--border) !important;
  border-radius: 12px !important;
  overflow: hidden !important;
  box-shadow: var(--shadow-lg) !important;
}

.maplibregl-ctrl-group button {
  width: 32px !important;
  height: 32px !important;
  border-bottom: 1px solid var(--border) !important;
  background: transparent !important;
  color: var(--text-main) !important;
}

.maplibregl-ctrl-group button:last-child {
  border-bottom: none !important;
}

.maplibregl-ctrl-group button:hover {
  background: var(--bg-surface-hover) !important;
  color: var(--primary) !important;
}

.maplibregl-ctrl-group button:active {
  background: var(--bg-surface-hover) !important;
}

.maplibregl-ctrl-group button .maplibregl-ctrl-icon {
  filter: var(--ctrl-icon-filter, none);
}

[data-theme="dark"] .maplibregl-ctrl-group button .maplibregl-ctrl-icon {
  filter: invert(1);
}

/* Custom buttons inside map control group (全景、我的位置) */
.map-ctrl-btn {
  display: flex !important;
  align-items: center !important;
  justify-content: center !important;
  color: var(--text-main) !important;
  font-size: 0.95rem !important;
  cursor: pointer;
  transition: color 0.15s ease, background-color 0.15s ease;
}

.map-ctrl-btn:hover {
  color: var(--primary) !important;
}

.map-ctrl-btn:active i {
  transform: scale(0.9);
}

/* Top Floating Bar (Aligned with map controls on the right) */
.top-bar {
  position: absolute;
  top: max(12px, env(safe-area-inset-top, 12px));
  left: 18px;
  right: 18px;
  z-index: 1000;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  pointer-events: none;
}

.top-bar > * {
  pointer-events: auto;
}

/* Compact Brand Badge with automatic shrinking on mobile */
.brand-badge {
  background: var(--bg-card);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  border: 1px solid var(--border);
  padding: 8px 14px;
  border-radius: 9999px;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  box-shadow: var(--shadow-lg);
  font-weight: 700;
  font-size: 0.92rem;
  color: var(--text-main);
  cursor: pointer;
  flex: 0 1 auto;
  min-width: 0;
  max-width: 320px;
}

.brand-badge span {
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  min-width: 0;
}

.brand-badge i {
  color: var(--primary);
  font-size: 1.05rem;
  flex-shrink: 0;
}

.top-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-shrink: 0;
}

/* Glass Buttons with strict size preservation */
.glass-btn {
  background: var(--bg-card);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  border: 1px solid var(--border);
  color: var(--text-main);
  padding: 8px 14px;
  border-radius: 9999px;
  font-size: 0.9rem;
  font-weight: 600;
  display: flex;
  align-items: center;
  gap: 6px;
  cursor: pointer;
  box-shadow: var(--shadow-lg);
  transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
  flex-shrink: 0;
  white-space: nowrap;
}

.glass-btn:active {
  transform: scale(0.96);
  opacity: 0.9;
}

/* Glass Menu Button (三條線漢堡選單) */
.glass-menu-btn {
  width: 42px !important;
  height: 42px !important;
  padding: 0 !important;
  display: flex !important;
  align-items: center !important;
  justify-content: center !important;
  border-radius: 12px !important;
  font-size: 1.22rem !important;
  color: var(--text-main) !important;
  background: var(--bg-card) !important;
  backdrop-filter: blur(16px) !important;
  -webkit-backdrop-filter: blur(16px) !important;
  border: 1px solid var(--border) !important;
  box-shadow: var(--shadow-lg) !important;
  cursor: pointer;
  flex-shrink: 0;
  transition: all 0.2s cubic-bezier(0.16, 1, 0.3, 1) !important;
}

.glass-menu-btn:hover {
  background: var(--bg-surface-hover) !important;
  color: var(--primary) !important;
  border-color: var(--primary) !important;
  transform: translateY(-1px);
}

.glass-menu-btn:active {
  transform: scale(0.92) !important;
}

.glass-btn.primary {
  background: var(--primary);
  border-color: var(--primary-hover);
  color: #ffffff;
}

.glass-icon-btn {
  width: 40px;
  height: 40px;
  min-width: 40px;
  min-height: 40px;
  border-radius: 50%;
  padding: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.avatar-img {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  object-fit: cover;
  border: 2px solid var(--primary);
}

/* Adaptive Add Button Text: 新增行程 > 新增 > ＋ */
.btn-text-full {
  display: inline;
}
.btn-text-short {
  display: none;
}

@media (max-width: 600px) {
  .btn-text-full {
    display: none;
  }
  .btn-text-short {
    display: inline;
  }
  .glass-btn.primary {
    padding: 8px 12px;
  }
}

@media (max-width: 420px) {
  .btn-text-full {
    display: none;
  }
  .btn-text-short {
    display: none;
  }
  .glass-btn.primary {
    width: 40px;
    height: 40px;
    min-width: 40px;
    min-height: 40px;
    border-radius: 50%;
    padding: 0;
    justify-content: center;
  }
  .brand-badge {
    padding: 8px 12px;
    font-size: 0.88rem;
  }
}

/* ==========================================================
   Mobile Bottom Sheet (Apple Maps style 3-tier swipe + snap)
   ========================================================== */
.bottom-sheet {
  position: absolute;
  bottom: 0; /* align flush to bottom; safe area handled by padding-bottom */
  left: 0;
  right: 0;
  z-index: 1001;
  background: var(--bg-surface);
  border-top: 1px solid var(--border);
  border-radius: 26px 26px 0 0;
  box-shadow: 0 -10px 40px rgba(0, 0, 0, 0.4);
  display: flex;
  flex-direction: column;
  height: 60vh;
  height: 60dvh;
  max-height: 94vh;
  max-height: 94dvh;
  /* push sheet content above home indicator / safe area */
  padding-bottom: max(16px, env(safe-area-inset-bottom, 16px));
  transition: transform 0.32s cubic-bezier(0.16, 1, 0.3, 1), height 0.32s cubic-bezier(0.16, 1, 0.3, 1);
  will-change: transform, height;
}

/* 3 Snap States on Mobile */
.bottom-sheet.state-collapsed {
  transform: translateY(calc(100% - 74px - env(safe-area-inset-bottom, 16px))) !important;
}

.bottom-sheet.state-mid {
  height: 55vh;
  height: 55dvh;
  transform: translateY(0) !important;
}

.bottom-sheet.state-full {
  height: 92vh;
  height: 92dvh;
  transform: translateY(0) !important;
}

.sheet-handle-wrap {
  width: 100%;
  padding: 10px 0 6px;
  display: flex;
  justify-content: center;
  cursor: grab;
  touch-action: none;
}

.sheet-handle {
  width: 42px;
  height: 5px;
  border-radius: 3px;
  background: var(--text-muted);
  opacity: 0.35;
}

.sheet-header {
  padding: 4px 16px 8px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  cursor: pointer;
  user-select: none;
}

.sheet-title-row {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
  width: 100%;
}

.sheet-plan-icon {
  width: 36px;
  height: 36px;
  border-radius: 10px;
  background: var(--primary-light);
  color: var(--primary);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.05rem;
  flex-shrink: 0;
  box-shadow: 0 2px 6px rgba(59, 130, 246, 0.15);
}

[data-theme="dark"] .sheet-plan-icon {
  background: rgba(59, 130, 246, 0.2);
  color: #60a5fa;
}

.sheet-title-text-group {
  display: flex;
  flex-direction: column;
  min-width: 0;
  flex: 1;
  gap: 2px;
}

.sheet-title {
  font-size: 1.02rem;
  font-weight: 700;
  color: var(--text-main);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  line-height: 1.25;
}

.sheet-collapsed-subinfo {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 0.75rem;
}

.badge-count {
  background: var(--primary-light);
  color: var(--primary);
  font-size: 0.72rem;
  padding: 2px 7px;
  border-radius: 12px;
  font-weight: 700;
  flex-shrink: 0;
}

.bottom-sheet.state-collapsed .quick-action-bar {
  display: none !important;
}

.sheet-content {
  overflow-y: auto;
  padding: 0 16px 20px;
  flex: 1;
  -webkit-overflow-scrolling: touch;
}

/* Compact Quick Action Pills with Hidden Scrollbar */
.quick-action-bar {
  display: flex;
  gap: 8px;
  padding: 0 16px 10px;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: none; /* Firefox */
  -ms-overflow-style: none; /* IE / Edge */
}

.quick-action-bar::-webkit-scrollbar {
  display: none; /* Chrome / Safari / Opera */
}

.action-pill {
  flex-shrink: 0;
  display: flex;
  align-items: center;
  gap: 5px;
  padding: 6px 12px;
  border-radius: 20px;
  background: var(--bg-surface);
  border: 1px solid var(--border);
  color: var(--text-main);
  font-size: 0.82rem;
  font-weight: 600;
  cursor: pointer;
  transition: 0.15s ease;
  white-space: nowrap;
}

.action-pill.nav-all {
  background: linear-gradient(135deg, #10b981 0%, #059669 100%);
  border: none;
  box-shadow: 0 4px 12px rgba(16, 185, 129, 0.3);
  color: #ffffff;
}

.action-pill.active {
  border-color: var(--primary);
  background: var(--primary-light);
  color: var(--primary);
}

.action-pill.edit-mode-active {
  border-color: var(--warning);
  background: rgba(245, 158, 11, 0.15);
  color: var(--warning);
}

/* Places List */
.places-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
  list-style: none;
  position: relative;
}

.place-card-wrapper {
  position: relative;
  border-radius: 16px;
}

.place-card {
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: 16px;
  background-clip: padding-box;
  padding: 10px 12px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  transition: transform 0.2s cubic-bezier(0.16, 1, 0.3, 1), box-shadow 0.2s ease, background-color 0.2s ease;
  position: relative;
  z-index: 2;
  user-select: none;
  touch-action: pan-y;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.05);
}

.place-card.completed {
  opacity: 0.6;
  border-color: transparent;
}

.place-card.completed .place-title {
  text-decoration: line-through;
  color: var(--text-muted);
}

.place-card.is-dragging {
  opacity: 0.95;
  position: fixed !important;
  z-index: 9999 !important;
  box-shadow: 0 16px 36px rgba(0, 0, 0, 0.35);
  transform: scale(1.03) !important;
  pointer-events: none;
}

.place-card-placeholder {
  border: 2px dashed var(--primary);
  background: var(--primary-light);
  border-radius: 16px;
  margin-bottom: 8px;
}

.place-left {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-shrink: 0;
}

.place-drag-handle {
  color: var(--text-muted);
  cursor: grab;
  font-size: 1.1rem;
  padding: 4px;
  touch-action: none;
}

.place-index {
  width: 24px;
  height: 24px;
  border-radius: 50%;
  background: var(--primary-light);
  color: var(--primary);
  font-weight: 700;
  font-size: 0.75rem;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.place-card.completed .place-index {
  background: var(--success-light);
  color: var(--success);
}

.place-info {
  flex: 1;
  min-width: 0;
  cursor: pointer;
}

.place-title {
  font-size: 0.92rem;
  font-weight: 600;
  color: var(--text-main);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  margin-bottom: 2px;
  display: flex;
  align-items: center;
  gap: 6px;
}

.via-tag {
  display: inline-flex;
  align-items: center;
  gap: 3px;
  padding: 1px 6px;
  border-radius: 6px;
  font-size: 0.68rem;
  font-weight: 700;
  background: rgba(245, 158, 11, 0.15);
  color: #f59e0b;
  border: 1px solid rgba(245, 158, 11, 0.3);
  flex-shrink: 0;
}

.place-card-via {
  background: rgba(245, 158, 11, 0.04);
}

.place-index.via-index {
  background: rgba(245, 158, 11, 0.15);
  color: #f59e0b;
}

.place-subtitle {
  font-size: 0.72rem;
  color: var(--text-muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.place-actions {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-shrink: 0;
}

.icon-btn-sm {
  width: 34px;
  height: 34px;
  border-radius: 50%;
  background: rgba(125, 125, 125, 0.1);
  border: 1px solid var(--border);
  color: var(--text-main);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.85rem;
  cursor: pointer;
  transition: 0.15s ease;
}

.icon-btn-sm:active {
  transform: scale(0.9);
}

.icon-btn-sm.check-btn {
  color: #94a3b8;
  background: transparent;
}

.place-card.completed .icon-btn-sm.check-btn {
  color: #10b981;
  background: var(--success-light);
}

.icon-btn-sm.nav-btn {
  color: var(--primary);
  background: var(--primary-light);
  border-color: rgba(96, 165, 250, 0.3);
}

[data-theme="dark"] .icon-btn-sm.nav-btn {
  color: #93c5fd;
  background: rgba(59, 130, 246, 0.25);
  border-color: rgba(147, 197, 253, 0.35);
}

[data-theme="dark"] .badge-count {
  background: rgba(59, 130, 246, 0.25);
  color: #93c5fd;
}

[data-theme="dark"] .place-index {
  background: rgba(59, 130, 246, 0.25);
  color: #93c5fd;
}

/* ==========================================================
   Desktop Floating Modal Panel (Strictly positioned on the RIGHT)
   ========================================================== */
.sheet-side-toggle {
  display: none;
}

@media (min-width: 900px) {
  #map {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    width: 100%;
    height: 100%;
  }

  .top-bar {
    left: 20px;
    right: 440px; /* Keep clear of right floating panel */
    transition: right 0.35s cubic-bezier(0.16, 1, 0.3, 1);
  }

  body.desktop-panel-hidden .top-bar {
    right: 20px;
  }

  /* Desktop brand badge wider to show full plan title */
  .brand-badge {
    max-width: 480px;
  }

  .brand-badge span {
    max-width: 380px;
  }

  /* Shift MapLibre controls when panel opens/closes */
  .maplibregl-ctrl-top-right {
    top: 74px !important;
    right: 440px !important;
    transition: right 0.35s cubic-bezier(0.16, 1, 0.3, 1);
  }

  .maplibregl-ctrl-bottom-right {
    right: 440px !important;
    transition: right 0.35s cubic-bezier(0.16, 1, 0.3, 1);
  }

  body.desktop-panel-hidden .maplibregl-ctrl-top-right,
  body.desktop-panel-hidden .maplibregl-ctrl-bottom-right {
    right: 20px !important;
  }

  /* Hide sheet handle on desktop (only used for mobile bottom sheet) */
  .sheet-handle-wrap {
    display: none !important;
  }

  .sheet-header {
    padding-top: 16px;
  }

  .bottom-sheet {
    position: absolute !important;
    top: 20px !important;
    right: 20px !important;
    left: auto !important;
    bottom: 20px !important;
    width: 390px !important;
    height: auto !important;
    max-height: none !important;
    border-radius: 24px !important;
    border: 1px solid var(--border) !important;
    box-shadow: 0 15px 40px rgba(0, 0, 0, 0.35) !important;
    transform: none !important;
    padding-bottom: 12px !important;
    transition: transform 0.35s cubic-bezier(0.16, 1, 0.3, 1) !important;
    overflow: visible;
  }

  /* Desktop Left Edge Fold/Toggle Arrow Button - seamlessly fused with bottom-sheet */
  .sheet-side-toggle {
    display: flex;
    position: absolute;
    top: 50%;
    left: -20px;
    transform: translateY(-50%);
    width: 21px;
    height: 60px;
    background: var(--bg-card);
    backdrop-filter: blur(28px);
    -webkit-backdrop-filter: blur(28px);
    border: 1px solid var(--border);
    border-right: none;
    border-radius: 12px 0 0 12px;
    color: var(--text-muted);
    align-items: center;
    justify-content: center;
    cursor: pointer;
    box-shadow: none;
    z-index: 10;
    transition: background-color 0.2s ease, color 0.2s ease, width 0.2s ease, left 0.2s ease;
  }

  .sheet-side-toggle:hover {
    color: var(--text-main);
    background: var(--bg-surface-hover);
    width: 23px;
    left: -22px;
  }

  .sheet-side-toggle i {
    font-size: 0.82rem;
    transition: transform 0.35s cubic-bezier(0.16, 1, 0.3, 1);
  }

  /* Collapsed state on Desktop: moves completely to the right edge, only arrow protrudes */
  .bottom-sheet.desktop-hidden {
    transform: translateX(calc(100% + 20px)) !important;
  }

  .bottom-sheet.desktop-hidden .sheet-side-toggle {
    border-right: 1px solid var(--border);
    border-radius: 12px 0 0 12px;
  }

  .bottom-sheet.desktop-hidden .sheet-side-toggle i {
    transform: rotate(180deg);
  }
}

/* Modals & Dialogs */
.modal-overlay {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 2500;
  background: rgba(0, 0, 0, 0.7);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.25s ease;
}

.modal-overlay.open {
  opacity: 1;
  pointer-events: auto;
}

.modal-card {
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: 24px;
  padding: 24px;
  width: 100%;
  max-width: 460px;
  max-height: 90vh;
  overflow-y: auto;
  box-shadow: 0 25px 50px -12px rgba(0, 0, 0, 0.6);
  transform: scale(0.95);
  transition: transform 0.25s cubic-bezier(0.16, 1, 0.3, 1);
  color: var(--text-main);
}

.modal-overlay.open .modal-card {
  transform: scale(1);
}

.modal-title {
  font-size: 1.25rem;
  font-weight: 700;
  margin-bottom: 8px;
  color: var(--text-main);
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.modal-desc {
  font-size: 0.85rem;
  color: var(--text-muted);
  margin-bottom: 16px;
  line-height: 1.4;
}

.modal-tabs {
  display: flex;
  gap: 8px;
  margin-bottom: 16px;
  border-bottom: 1px solid var(--border);
  padding-bottom: 8px;
}

.modal-tab-btn {
  background: none;
  border: none;
  color: var(--text-muted);
  padding: 6px 12px;
  border-radius: 8px;
  font-weight: 600;
  font-size: 0.9rem;
  cursor: pointer;
  transition: 0.15s ease;
}

.modal-tab-btn.active {
  background: var(--primary-light);
  color: var(--primary);
}

.form-group {
  margin-bottom: 14px;
}

.form-label {
  display: block;
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--text-muted);
  margin-bottom: 6px;
}

.form-input, .form-textarea, .form-select {
  width: 100%;
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 10px 14px;
  color: var(--text-main);
  font-size: 0.95rem;
  outline: none;
  transition: border-color 0.2s ease;
}

.form-textarea {
  resize: none;
  min-height: 80px;
}

.form-input:focus, .form-textarea:focus, .form-select:focus {
  border-color: var(--primary);
}

.modal-buttons {
  display: flex;
  gap: 10px;
  margin-top: 20px;
}

.btn-primary {
  flex: 1;
  background: var(--primary);
  border: none;
  border-radius: 12px;
  padding: 12px;
  color: #ffffff;
  font-weight: 600;
  font-size: 0.95rem;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
}

.btn-secondary {
  flex: 1;
  background: rgba(125, 125, 125, 0.12);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 12px;
  color: var(--text-main);
  font-weight: 600;
  font-size: 0.95rem;
  cursor: pointer;
}

/* User Settings Item in Profile Modal */
.user-settings-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 14px;
  background: var(--bg-input);
  border-radius: 14px;
  margin-bottom: 14px;
}

/* Custom Marker (Rock-solid pinning without drag vibration) */
.custom-pin-marker {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 32px;
  border-radius: 50%;
  background: #3b82f6;
  color: #ffffff;
  font-weight: 700;
  font-size: 13px;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.45);
  border: 2.5px solid #ffffff;
  cursor: pointer;
  user-select: none;
  /* 禁止對 transform 使用 transition，避免拖曳地圖時與 MapLibre 引擎座標插值衝突造成晃動 */
  transition: background-color 0.2s ease, box-shadow 0.2s ease;
  will-change: auto;
}

.custom-pin-marker.completed {
  background: #10b981;
}

.custom-pin-marker.via-marker {
  background: #f59e0b;
  border-radius: 8px; /* 方形圓角區隔一般圓形站點 */
}

.popup-badge.via-badge {
  background: rgba(245, 158, 11, 0.2);
  color: #f59e0b;
}

.custom-pin-marker:hover {
  box-shadow: 0 6px 18px rgba(0, 0, 0, 0.55);
}

/* Drawer & Backdrop */
.drawer-backdrop {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(0, 0, 0, 0.6);
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
  z-index: 2090;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.3s ease;
}

.drawer-backdrop.open {
  opacity: 1;
  pointer-events: auto;
}

.drawer {
  position: fixed;
  top: 0;
  left: 0;
  bottom: 0;
  width: 84%;
  max-width: 340px;
  background: var(--bg-surface);
  border-right: 1px solid var(--border);
  z-index: 2100;
  transform: translateX(-100%);
  transition: transform 0.3s cubic-bezier(0.16, 1, 0.3, 1);
  display: flex;
  flex-direction: column;
  padding: max(16px, calc(env(safe-area-inset-top, 0px) + 12px)) 18px max(20px, calc(env(safe-area-inset-bottom, 0px) + 16px));
  box-shadow: 20px 0 50px rgba(0, 0, 0, 0.5);
}

.drawer.open {
  transform: translateX(0);
}

.drawer-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 14px;
  padding-bottom: 10px;
  border-bottom: 1px solid var(--border);
}

.drawer-title {
  font-size: 1.15rem;
  font-weight: 700;
  color: var(--text-main);
}

.plan-items-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
  overflow-y: auto;
  flex: 1;
}

.plan-item-card {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 12px;
  background: rgba(125, 125, 125, 0.08);
  border: 1px solid var(--border);
  border-radius: 12px;
  transition: 0.15s ease;
}

.plan-item-card.active {
  background: var(--primary-light);
  border-color: var(--primary);
}

.plan-item-btn {
  background: none;
  border: none;
  color: var(--text-main);
  font-size: 0.9rem;
  font-weight: 600;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 8px;
  flex: 1;
  text-align: left;
}

.plan-item-card.active .plan-item-btn {
  color: var(--primary);
}

/* Multi-nav Checklist Beautification */
.multi-nav-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin: 14px 0;
  max-height: 220px;
  overflow-y: auto;
  padding-right: 4px;
}

.multi-nav-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 12px;
  border-radius: 12px;
  background: var(--bg-surface-hover);
  border: 1px solid var(--border);
  cursor: pointer;
  user-select: none;
  transition: all 0.15s ease;
}

.multi-nav-item:hover {
  border-color: var(--primary);
}

.multi-nav-checkbox-custom {
  width: 20px;
  height: 20px;
  border-radius: 6px;
  border: 2px solid var(--text-muted);
  display: flex;
  align-items: center;
  justify-content: center;
  color: transparent;
  transition: all 0.15s ease;
  flex-shrink: 0;
}

.multi-nav-item input[type="checkbox"] {
  display: none;
}

.multi-nav-item input[type="checkbox"]:checked + .multi-nav-checkbox-custom {
  background: var(--primary);
  border-color: var(--primary);
  color: #ffffff;
}

.multi-nav-item-title {
  font-size: 0.9rem;
  font-weight: 600;
  color: var(--text-main);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  flex: 1;
}

/* Navigation App Choices */
.nav-app-choice {
  display: flex;
  gap: 14px;
  margin-top: 16px;
}

.nav-app-btn {
  flex: 1;
  padding: 16px;
  background: var(--bg-surface-hover);
  border: 1px solid var(--border);
  border-radius: 16px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  cursor: pointer;
  transition: 0.2s ease;
  color: var(--text-main) !important;
}

.nav-app-btn span {
  color: var(--text-main) !important;
  font-weight: 600;
  font-size: 0.92rem;
}

.nav-app-btn:active {
  transform: scale(0.96);
  opacity: 0.9;
}

.nav-app-btn i {
  font-size: 2.2rem;
}

.nav-app-btn.google i {
  color: #ea4335;
}

.nav-app-btn.apple i {
  color: var(--text-main);
}

/* Toast */
.toast {
  position: fixed;
  bottom: 90px;
  left: 50%;
  transform: translateX(-50%) translateY(20px);
  background: var(--bg-surface);
  border: 1px solid var(--border);
  color: var(--text-main);
  padding: 10px 22px;
  border-radius: 9999px;
  font-size: 0.88rem;
  font-weight: 600;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.45);
  z-index: 3000;
  opacity: 0;
  pointer-events: none;
  transition: all 0.25s cubic-bezier(0.16, 1, 0.3, 1);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 9px;
  white-space: nowrap;
  max-width: 90vw;
}

.toast i {
  font-size: 0.96rem;
  flex-shrink: 0;
}

.toast.show {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

/* PWA Update Toast */
.update-toast {
  position: fixed;
  bottom: max(24px, env(safe-area-inset-bottom, 24px));
  left: 50%;
  transform: translateX(-50%) translateY(80px);
  background: var(--bg-surface);
  border: 1px solid var(--border);
  color: var(--text-main);
  padding: 10px 12px 10px 18px;
  border-radius: 9999px;
  font-size: 0.85rem;
  font-weight: 600;
  box-shadow: var(--shadow-lg);
  z-index: 4000;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.3s ease, transform 0.3s cubic-bezier(0.16, 1, 0.3, 1);
  display: flex;
  align-items: center;
  gap: 10px;
  white-space: nowrap;
}

.update-toast.visible {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
  pointer-events: auto;
}

.update-toast button {
  background: var(--primary);
  color: #fff;
  border: none;
  border-radius: 9999px;
  padding: 5px 14px;
  font-size: 0.82rem;
  font-weight: 700;
  cursor: pointer;
  transition: background 0.15s ease;
}

.update-toast button:hover {
  background: var(--primary-hover);
}

/* ==========================================================
   MapLibre Custom Popup (Enlarged & Polished)
   ========================================================== */
.maplibregl-popup {
  z-index: 1000 !important;
  max-width: 330px !important;
}

.maplibregl-popup-content {
  background: var(--bg-surface) !important;
  color: var(--text-main) !important;
  border: 1px solid var(--border) !important;
  border-radius: 18px !important;
  box-shadow: 0 20px 42px rgba(0, 0, 0, 0.3) !important;
  padding: 16px !important;
  position: relative;
}

/* Popup Close Button */
.maplibregl-popup-close-button {
  top: 10px !important;
  right: 10px !important;
  width: 28px !important;
  height: 28px !important;
  border-radius: 50% !important;
  display: flex !important;
  align-items: center !important;
  justify-content: center !important;
  font-size: 1.15rem !important;
  color: var(--text-muted) !important;
  background: var(--bg-surface-hover) !important;
  border: none !important;
  transition: all 0.15s ease !important;
  padding: 0 !important;
  cursor: pointer !important;
  line-height: 1 !important;
}

.maplibregl-popup-close-button:hover {
  background: var(--border) !important;
  color: var(--text-main) !important;
}

/* Popup Tip Arrow: 完全隱藏箭頭，防止拖曳時忽上忽下閃爍 */
.maplibregl-popup-tip {
  display: none !important;
}

/* Popup Inner Elements */
.custom-popup-content {
  display: flex;
  flex-direction: column;
  gap: 8px;
  min-width: 240px;
}

.popup-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 2px;
  padding-right: 28px; /* Room for close button */
}

.popup-badge {
  font-size: 0.75rem;
  font-weight: 700;
  padding: 3px 9px;
  border-radius: 9999px;
  display: inline-flex;
  align-items: center;
  gap: 4px;
}

.popup-badge.index-badge {
  background: var(--primary);
  color: #ffffff;
}

.popup-badge.status-badge {
  background: rgba(100, 116, 139, 0.15);
  color: var(--text-muted);
}

.popup-badge.status-badge.completed {
  background: rgba(16, 185, 129, 0.2);
  color: #10b981;
}

.popup-title {
  font-size: 1.18rem;
  font-weight: 700;
  line-height: 1.35;
  color: var(--text-main);
  margin: 0;
  word-break: break-word;
}

.popup-meta-row {
  display: flex;
  align-items: flex-start;
  gap: 7px;
  font-size: 0.88rem;
  color: var(--text-muted);
  line-height: 1.4;
}

.popup-meta-row i {
  color: var(--primary);
  margin-top: 3px;
  font-size: 0.95rem;
  flex-shrink: 0;
}

.popup-note-box {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 8px 10px;
  font-size: 0.85rem;
  color: var(--text-main);
  display: flex;
  align-items: flex-start;
  gap: 7px;
  line-height: 1.45;
}

.popup-note-box i {
  color: var(--primary);
  margin-top: 3px;
  flex-shrink: 0;
}

.popup-coords-row {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 0.76rem;
  color: var(--text-muted);
  font-family: monospace;
}

.popup-coords-row i {
  color: var(--text-muted);
}

/* Action Buttons Grid */
.popup-actions-grid {
  display: grid;
  grid-template-columns: 1.25fr 1.25fr 0.9fr;
  gap: 7px;
  margin-top: 6px;
}

.popup-action-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 9px 10px;
  border-radius: 10px;
  font-size: 0.88rem;
  font-weight: 600;
  cursor: pointer;
  border: none;
  transition: all 0.15s ease;
  white-space: nowrap;
}

.popup-action-btn:active {
  transform: scale(0.95);
}

.popup-action-btn.btn-nav {
  background: var(--primary);
  color: #ffffff;
  box-shadow: 0 2px 8px rgba(59, 130, 246, 0.3);
}

.popup-action-btn.btn-nav:hover {
  background: var(--primary-hover);
}

.popup-action-btn.btn-check {
  background: rgba(16, 185, 129, 0.16);
  color: #10b981;
  border: 1px solid rgba(16, 185, 129, 0.35);
}

.popup-action-btn.btn-check:hover {
  background: rgba(16, 185, 129, 0.28);
}

.popup-action-btn.btn-check.is-completed {
  background: rgba(100, 116, 139, 0.15);
  color: var(--text-muted);
  border: 1px solid var(--border);
}

.popup-action-btn.btn-edit {
  background: var(--bg-surface-hover);
  color: var(--text-main);
  border: 1px solid var(--border);
}

.popup-action-btn.btn-edit:hover {
  background: var(--border);
}
