/* ===== How to Reach — minimal, mobile-first ===== */
* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { height: 100%; margin: 0; font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; }

#map { position: fixed; inset: 0; z-index: 0; background: #eef0f2; -webkit-touch-callout: none; }

.btn {
  border: 0; border-radius: 8px; padding: 8px 14px; font-size: 14px;
  background: #e9ecef; color: #222; cursor: pointer; text-decoration: none;
  display: inline-flex; align-items: center; gap: 6px;
}
.btn.primary { background: #e63946; color: #fff; }
.btn.ghost   { background: transparent; color: #555; }
.btn.wa      { background: #25d366; color: #fff; }

/* ---------- Top bar ---------- */
#topbar {
  position: fixed; top: 8px; left: 8px; right: 8px; z-index: 1000;
  display: flex; gap: 8px; pointer-events: none;
}
#topbar input {
  pointer-events: auto;
  border: 0; border-radius: 10px; padding: 10px 12px; font-size: 14px;
  background: #fff; box-shadow: 0 2px 8px rgba(0,0,0,.15); outline: none;
}
#route-title { flex: 1 1 45%; min-width: 0; }
#search-wrap { flex: 1 1 55%; min-width: 0; position: relative; }
#search-box  { width: 100%; }
#search-results {
  pointer-events: auto;
  position: absolute; top: 44px; left: 0; right: 0; z-index: 1001;
  background: #fff; border-radius: 10px; box-shadow: 0 4px 14px rgba(0,0,0,.2);
  overflow: hidden; max-height: 40vh; overflow-y: auto;
}
#search-results div {
  padding: 10px 12px; font-size: 13px; cursor: pointer;
  border-bottom: 1px solid #f0f0f0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
#search-results div:hover { background: #f6f6f6; }

/* ---------- Viewer banner ---------- */
#viewer-banner {
  position: fixed; top: 8px; left: 8px; right: 8px; z-index: 1000;
  background: #fff; border-radius: 12px; box-shadow: 0 2px 10px rgba(0,0,0,.18);
  padding: 10px 14px; display: flex; align-items: center; gap: 10px;
}
#viewer-title { flex: 1; font-weight: 600; font-size: 15px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* ---------- Toolbar ---------- */
#toolbar {
  position: fixed; z-index: 1000;
  left: 50%; transform: translateX(-50%);
  bottom: calc(10px + env(safe-area-inset-bottom));
  display: flex; gap: 2px; align-items: center;
  background: #fff; border-radius: 14px; box-shadow: 0 4px 16px rgba(0,0,0,.22);
  padding: 6px; max-width: calc(100vw - 16px); overflow-x: auto;
}
.tool {
  border: 0; background: transparent; border-radius: 10px;
  display: flex; flex-direction: column; align-items: center; gap: 2px;
  padding: 6px 9px; cursor: pointer; min-width: 54px; flex: 0 0 auto;
}
.tool:active { background: #f1f3f5; }
.tool.active { background: #ffe3e6; }
.ticon  { font-size: 18px; line-height: 1; }
.tlabel { font-size: 10px; color: #444; white-space: nowrap; }
.tsep { width: 1px; align-self: stretch; background: #e9ecef; margin: 4px 2px; flex: 0 0 auto; }

/* ---------- Autosave status badge ---------- */
#save-status {
  position: fixed; z-index: 1100; top: 54px; left: 50%; transform: translateX(-50%);
  background: rgba(0,0,0,.72); color: #fff; font-size: 12px;
  padding: 4px 11px; border-radius: 10px; pointer-events: none;
  box-shadow: 0 2px 8px rgba(0,0,0,.2);
}

/* ---------- Undo / action history ---------- */
#history {
  position: fixed; z-index: 1200; top: 56px; left: 8px;
  display: flex; flex-direction: column; gap: 6px; max-width: 240px;
}
#history-bar { display: flex; gap: 6px; }
#history .btn { background: #fff; box-shadow: 0 2px 8px rgba(0,0,0,.18); }
#history-toggle { padding: 8px 11px; }
#history-list {
  margin: 0; padding: 6px; list-style: none;
  background: #fff; border-radius: 10px; box-shadow: 0 4px 16px rgba(0,0,0,.22);
  max-height: 42vh; overflow-y: auto; font-size: 13px;
}
#history-list li {
  padding: 7px 10px; border-radius: 7px; cursor: pointer; color: #333;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
#history-list li::before { content: '↶ '; opacity: .45; }
#history-list li:hover { background: #fdecee; color: #e63946; }

/* ---------- Hint strip ---------- */
#hint {
  position: fixed; z-index: 1000; left: 50%; transform: translateX(-50%);
  bottom: calc(84px + env(safe-area-inset-bottom));
  background: rgba(33,37,41,.92); color: #fff; font-size: 13px;
  padding: 8px 14px; border-radius: 20px; max-width: 90vw; text-align: center;
}

/* ---------- Waypoint picker ---------- */
#wp-picker {
  position: fixed; z-index: 1002; left: 50%; transform: translateX(-50%);
  bottom: calc(84px + env(safe-area-inset-bottom));
  background: #fff; border-radius: 12px; box-shadow: 0 4px 16px rgba(0,0,0,.22);
  display: flex; gap: 4px; padding: 6px; flex-wrap: wrap; justify-content: center;
}
#wp-picker button {
  border: 0; background: #f6f7f8; border-radius: 8px; padding: 8px 10px;
  font-size: 13px; cursor: pointer;
}

/* ---------- Map pins (divIcons) ---------- */
.pin { position: relative; width: 34px; height: 42px; }
.pin .pin-bubble {
  position: absolute; top: 0; left: 0;
  width: 34px; height: 34px; border-radius: 50% 50% 50% 0;
  transform: rotate(-45deg);
  display: flex; align-items: center; justify-content: center;
  box-shadow: 0 2px 6px rgba(0,0,0,.35);
  background: #fff; border: 2px solid #888;
}
.pin .pin-bubble span { transform: rotate(45deg); font-size: 16px; }
/* Bootstrap-icon pins: counter-rotate so the glyph sits upright in the teardrop */
.pin .pin-bubble .bi { transform: rotate(45deg); font-size: 16px; line-height: 1; color: #555; }
.pin.start .pin-bubble { border-color: #2a9d8f; background: #e6f6f4; }
.pin.end   .pin-bubble { border-color: #e63946; background: #fdecee; }
.pin.start .pin-bubble .bi { color: #2a9d8f; }
.pin.end   .pin-bubble .bi { color: #e63946; }

.sim-arrow {
  width: 26px; height: 26px; border-radius: 50%;
  background: #1d6feb; color: #fff; display: flex; align-items: center; justify-content: center;
  font-size: 14px; box-shadow: 0 0 0 4px rgba(29,111,235,.25), 0 2px 6px rgba(0,0,0,.3);
}

.note-tip {
  background: #fff; border: 1px solid #f4a261; border-radius: 8px;
  padding: 2px 8px; font-size: 12px; font-weight: 600; color: #333;
  box-shadow: 0 2px 6px rgba(0,0,0,.15);
}
.note-tip::before { border-top-color: #f4a261; }
/* Attention blink when the simulation / live position passes a noted point.
   Animate colour + glow only — Leaflet owns the tooltip's transform for positioning. */
.note-tip.note-pulse {
  animation: note-pulse .5s ease-in-out 0s 5;
  z-index: 1000;
}
@keyframes note-pulse {
  0%, 100% { background: #fff;     box-shadow: 0 2px 6px rgba(0,0,0,.15);   border-color: #f4a261; }
  50%      { background: #fff3e0;  box-shadow: 0 0 0 7px rgba(244,162,97,.5); border-color: #e63946; }
}

/* ---------- Locate me ---------- */
.locate-btn { font-size: 15px; }

/* ---------- Check in Google Maps ---------- */
.gmaps-btn {
  font-weight: 700; font-size: 16px; color: #4285f4;
  font-family: "Segoe UI", system-ui, sans-serif;
}
.me-dot {
  width: 14px; height: 14px; border-radius: 50%;
  background: #1d6feb; border: 3px solid #fff;
  box-shadow: 0 1px 4px rgba(0,0,0,.4);
  animation: me-pulse 2s ease-out infinite;
}
@keyframes me-pulse {
  0%   { box-shadow: 0 0 0 0 rgba(29,111,235,.45), 0 1px 4px rgba(0,0,0,.4); }
  70%  { box-shadow: 0 0 0 16px rgba(29,111,235,0), 0 1px 4px rgba(0,0,0,.4); }
  100% { box-shadow: 0 0 0 0 rgba(29,111,235,0), 0 1px 4px rgba(0,0,0,.4); }
}

/* ---------- Map context menu (right-click / long-press) ---------- */
#ctx-menu {
  position: fixed; z-index: 1500;
  background: #fff; border-radius: 10px; box-shadow: 0 4px 16px rgba(0,0,0,.25);
  padding: 4px; min-width: 190px; overflow: hidden;
}
#ctx-menu button, #ctx-menu a {
  display: flex; align-items: center; gap: 8px; width: 100%;
  border: 0; background: transparent; border-radius: 7px;
  padding: 10px 12px; font-size: 14px; text-align: left; cursor: pointer;
  color: #222; text-decoration: none; box-sizing: border-box;
}
#ctx-menu button:active, #ctx-menu button:hover,
#ctx-menu a:active, #ctx-menu a:hover { background: #f1f3f5; }

/* ---------- Simulation panel ---------- */
#sim-panel {
  position: fixed; z-index: 1001; left: 50%; transform: translateX(-50%);
  bottom: calc(10px + env(safe-area-inset-bottom));
  background: #fff; border-radius: 14px; box-shadow: 0 4px 16px rgba(0,0,0,.22);
  display: flex; align-items: center; gap: 10px; padding: 10px 14px;
  max-width: calc(100vw - 16px); flex-wrap: wrap; justify-content: center;
}
.sim-speed { display: flex; align-items: center; gap: 6px; font-size: 12px; color: #555; }
.sim-speed input { width: 110px; }
.sim-follow { font-size: 12px; color: #555; display: flex; align-items: center; gap: 4px; }

/* ---------- Share modal ---------- */
.modal {
  position: fixed; inset: 0; z-index: 2000;
  background: rgba(0,0,0,.45);
  display: flex; align-items: center; justify-content: center; padding: 16px;
}
.modal-card {
  background: #fff; border-radius: 16px; padding: 20px;
  width: 100%; max-width: 360px; text-align: center;
  display: flex; flex-direction: column; gap: 12px;
}
.modal-card h3 { margin: 0; font-size: 17px; }
#share-url { width: 100%; border: 1px solid #ddd; border-radius: 8px; padding: 9px 10px; font-size: 12px; }
.share-actions { display: flex; gap: 8px; justify-content: center; }
#share-qr { display: flex; justify-content: center; padding: 6px 0; }
#share-qr img, #share-qr canvas { border: 6px solid #fff; }
#share-result { display: flex; flex-direction: column; gap: 12px; }
#share-busy { color: #777; font-size: 14px; padding: 12px 0; }
#share-embed { text-align: left; }
#share-embed summary { cursor: pointer; font-size: 13px; color: #555; }
#share-embed textarea {
  width: 100%; box-sizing: border-box; margin: 8px 0;
  border: 1px solid #ddd; border-radius: 8px; padding: 8px;
  font: 11px/1.4 monospace; resize: vertical;
}

/* ---------- Floating dialogs (replace native prompt/confirm) ---------- */
.ask-modal {
  position: fixed; inset: 0; z-index: 2500;
  background: rgba(0,0,0,.45);
  display: flex; align-items: center; justify-content: center; padding: 16px;
  animation: ask-fade .12s ease;
}
.ask-card {
  background: #fff; border-radius: 16px; padding: 18px;
  width: 100%; max-width: 360px;
  display: flex; flex-direction: column; gap: 14px;
  box-shadow: 0 12px 40px rgba(0,0,0,.25);
}
.ask-card h3 { margin: 0; font-size: 16px; color: #222; }
.ask-msg { margin: 0; font-size: 14px; color: #444; line-height: 1.4; }
.ask-input {
  width: 100%; box-sizing: border-box;
  border: 1px solid #ccc; border-radius: 10px;
  padding: 11px 12px; font-size: 15px; outline: none;
}
.ask-input:focus { border-color: #e63946; box-shadow: 0 0 0 3px rgba(230,57,70,.15); }
.ask-actions { display: flex; gap: 8px; justify-content: flex-end; }
.ask-actions .btn { padding: 9px 16px; }
.btn.danger { background: #e63946; color: #fff; }
@keyframes ask-fade { from { opacity: 0; } to { opacity: 1; } }

/* Icon picker grid (start/end/waypoint icon chooser) */
.icon-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; }
.icon-opt {
  border: 1px solid #ddd; border-radius: 10px; background: #fff;
  padding: 10px 0; font-size: 20px; cursor: pointer; color: #444;
  display: flex; align-items: center; justify-content: center;
}
.icon-opt:hover { background: #f6f7f8; }
.icon-opt.sel { border-color: #e63946; box-shadow: 0 0 0 3px rgba(230,57,70,.15); color: #e63946; }

/* Phone: dock to the bottom as a sheet, clear of the on-screen keyboard */
@media (max-width: 560px) {
  .ask-modal { align-items: flex-end; padding: 0; }
  .ask-card {
    max-width: none; border-radius: 16px 16px 0 0;
    padding: 18px 16px calc(18px + env(safe-area-inset-bottom));
    animation: ask-slide .18s ease;
  }
  @keyframes ask-slide { from { transform: translateY(100%); } to { transform: translateY(0); } }
}

/* ---------- In-app Google panel ---------- */
.gmap-card {
  max-width: 760px; width: 100%; height: min(80vh, 620px);
  padding: 0; overflow: hidden; gap: 0;
}
.gmap-head {
  display: flex; align-items: center; gap: 8px;
  padding: 8px 10px; border-bottom: 1px solid #eee;
}
.gmap-tabs { display: flex; gap: 4px; flex: 1; }
.gmap-tab {
  border: 0; background: #f1f3f5; border-radius: 8px;
  padding: 7px 12px; font-size: 13px; cursor: pointer; color: #444;
}
.gmap-tab.active { background: #ffe3e6; color: #c1121f; font-weight: 600; }
#gmap-ext { padding: 7px 10px; font-size: 13px; }
#gmap-close { padding: 7px 10px; font-size: 15px; }
#gmap-frame { flex: 1; width: 100%; border: 0; display: block; }

@media (max-width: 700px) {
  .gmap-card { max-width: 100%; height: 88vh; border-radius: 12px; }
  #gmap-ext { font-size: 12px; padding: 7px 8px; }
}

/* ---------- Toast ---------- */
#toast {
  position: fixed; z-index: 3000; left: 50%; transform: translateX(-50%);
  top: 64px;
  background: rgba(33,37,41,.95); color: #fff; font-size: 13px;
  padding: 10px 16px; border-radius: 10px; max-width: 90vw; text-align: center;
  box-shadow: 0 4px 14px rgba(0,0,0,.3);
}

/* Hide Geoman's own toolbar — we use our own buttons */
.leaflet-pm-toolbar { display: none !important; }

/* Slightly larger Leaflet attribution tap targets are fine; keep it subtle */
.leaflet-control-attribution { font-size: 10px; opacity: .75; }

@media (min-width: 700px) {
  #topbar { left: 50%; right: auto; transform: translateX(-50%); width: 640px; }
  #viewer-banner { left: 50%; right: auto; transform: translateX(-50%); width: 560px; }
  .tlabel { font-size: 11px; }
}
