:root {
  --bg: #f4f2ee;
  --surface: #ffffff;
  --glass: rgba(251, 247, 241, .72);
  --glass-strong: rgba(252, 249, 244, .86);
  --glass-blue: rgba(205, 245, 255, .76);
  --line: rgba(38, 34, 30, .14);
  --line-2: rgba(38, 34, 30, .22);
  --text: #221d17;
  --muted: #66706c;
  --faint: #6e776f;
  --accent: #e8932e;
  --accent-strong: #c2761d;
  --accent-blue: #e8932e;
  --start: #18b63f;
  --end: #e02828;
  --sidebar-w: 360px;
  --topbar-h: 70px;
  --bottom-nav-h: 84px;
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  color: var(--text);
  background: var(--bg);
  overflow: hidden;
  -webkit-font-smoothing: antialiased;
}
button,
input { font: inherit; }
#app {
  position: relative;
  height: 100vh;
  width: 100vw;
  overflow: hidden;
  background: #ece9e4;
}

/* ---------- Top route chrome ---------- */
#topbar {
  position: absolute;
  z-index: 12;
  top: max(14px, env(safe-area-inset-top));
  left: 24px;
  right: 24px;
  height: var(--topbar-h);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
  padding: 8px 14px;
  pointer-events: none;
}
.brand,
.top-right {
  pointer-events: auto;
}
.brand {
  min-width: 0;
  display: flex;
  align-items: center;
  gap: 13px;
}
.logo {
  width: 58px;
  height: 58px;
  border-radius: 15px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 34px;
  background: #ffffff;
  border: 1px solid rgba(38,34,30,.1);
  box-shadow: 0 4px 12px rgba(38,34,30,.12);
}
.logo-cube { width: 82%; height: 82%; display: block; }
.bname {
  display: none;
}
.bsub {
  max-width: min(48vw, 520px);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  color: rgba(20, 27, 25, .74);
  font-size: 28px;
  line-height: 1.05;
  font-weight: 700;
  text-shadow: 0 1px 0 rgba(255,255,255,.32);
}
.top-right {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 12px;
  min-width: 0;
}
#counts {
  display: inline-flex;
  align-items: center;
  min-height: 38px;
  padding: 8px 12px;
  border-radius: 19px;
  color: rgba(7, 67, 33, .8);
  background: rgba(252,250,247,.95);
  font-size: 13px;
  font-weight: 700;
}
.round-action,
#upload-btn,
.go-action {
  border: 1px solid rgba(255,255,255,.62);
  background: rgba(252,244,233,.96);
  color: #07351a;
  box-shadow: 0 8px 24px rgba(23, 74, 34, .16), inset 0 1px 0 rgba(255,255,255,.58);
  cursor: pointer;
}
.round-action {
  width: 58px;
  height: 58px;
  border-radius: 50%;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 27px;
}
/* "More" lives in the bottom bar on mobile; on desktop it's a topbar button. */
#top-more { display: none; }
@media (min-width: 901px) { #top-more { display: inline-flex; } }
.round-action:hover,
#upload-btn:hover,
.go-action:hover {
  color: var(--accent);
  border-color: rgba(232,147,46,.5);
}
.round-action.danger {
  color: #8d2222;
}
.round-action.danger:hover {
  color: var(--end);
}
#clear-map-btn[hidden] {
  display: none;
}
.go-action {
  min-width: 112px;
  height: 58px;
  border-radius: 29px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 0 22px;
  font-size: 24px;
  font-weight: 600;
}
.go-action i {
  font-size: 22px;
}
#upload-btn {
  min-height: 42px;
  border-radius: 21px;
  display: inline-flex;
  align-items: center;
  gap: 7px;
  padding: 0 14px;
  color: #084a24;
  font-size: 13px;
  font-weight: 600;
}
#upload-btn.loading {
  opacity: .72;
  pointer-events: none;
}

/* ---------- Fullscreen map layout ---------- */
#body {
  position: absolute;
  inset: 0;
}
#map {
  position: absolute;
  inset: 0;
  min-width: 0;
  background: #ece9e4;
  overflow: hidden;
}
#map-canvas {
  position: absolute;
  inset: 0;
  /* Confine the map + its pins to their own stacking context so markers
     (inline z-index up to ~35) can never paint over the UI controls
     (pin-card, Otimizar button, route badge, rail — z-index 8–10). */
  z-index: 0;
  isolation: isolate;
}
#map-canvas .mapboxgl-ctrl-bottom-left,
#map-canvas .mapboxgl-ctrl-bottom-right {
  transform: translateY(-92px);
}
.mapboxgl-ctrl-logo,
.mapboxgl-ctrl-attrib {
  opacity: .75;
}
#sidebar {
  position: absolute;
  z-index: 9;
  left: 16px;
  top: calc(var(--topbar-h) + 22px);
  bottom: calc(var(--bottom-nav-h) + 26px);
  width: var(--sidebar-w);
  display: flex;
  flex-direction: column;
  min-height: 0;
  overflow: hidden;
  border: 1px solid rgba(255,255,255,.64);
  border-radius: 16px;
  background: rgba(255,255,255,.97);
  box-shadow: 0 18px 48px rgba(17, 42, 31, .19);
  transform: translateX(calc(-100% - 24px));
  transition: transform .2s ease;
}
#sidebar.open {
  transform: translateX(0);
}

/* Mobile: when the panel is NOT open it must be fully gone (the slide-out
   transform left it partially visible on some viewports, so it looked like it
   kept opening on its own). display:none is bulletproof. */
@media (max-width: 900px) {
  #sidebar:not(.open) { display: none; }
}

/* ---------- Trip panel ---------- */
#trip {
  padding: 16px;
  border-bottom: 1px solid var(--line);
  display: flex;
  flex-direction: column;
  gap: 9px;
}
.sec-label {
  color: #7d8682;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: .42px;
  text-transform: uppercase;
}
.fld {
  display: flex;
  align-items: center;
  gap: 11px;
  min-height: 48px;
  padding: 9px 12px;
  border: 1px solid rgba(22,60,40,.14);
  border-radius: 14px;
  background: rgba(255,255,255,.72);
}
.fld .dot {
  width: 12px;
  height: 12px;
  flex: 0 0 12px;
  border-radius: 50%;
}
.fld .dot.start { background: var(--start); }
.fld .dot.end { background: var(--end); }
.fld-body { min-width: 0; flex: 1; }
.fld-k {
  color: var(--muted);
  font-size: 11px;
  line-height: 1.1;
}
.fld-v {
  margin-top: 2px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  font-size: 13.5px;
  font-weight: 700;
}
.fld-act {
  width: 32px;
  height: 32px;
  flex: 0 0 32px;
  display: flex;
  align-items: center;
  justify-content: center;
  border: 1px solid var(--line-2);
  border-radius: 10px;
  background: rgba(255,255,255,.82);
  color: var(--muted);
  cursor: pointer;
  font-size: 17px;
}
.fld-act:hover { color: var(--accent); border-color: rgba(232,147,46,.45); }
.seg {
  display: flex;
  gap: 7px;
}
.seg-btn {
  flex: 1;
  padding: 8px;
  border: 1px solid var(--line-2);
  border-radius: 11px;
  background: rgba(255,255,255,.74);
  color: #5a6660;
  cursor: pointer;
  font-size: 12.5px;
  font-weight: 700;
}
.seg-btn.active {
  background: rgba(250,228,200,.92);
  border-color: rgba(232,147,46,.45);
  color: var(--accent-strong);
}
.btnp {
  min-height: 46px;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  border: 0;
  border-radius: 15px;
  background: var(--accent);
  color: #fff;
  cursor: pointer;
  font-size: 14px;
  font-weight: 600;
  box-shadow: 0 8px 20px rgba(232,147,46,.22);
}
.btnp:disabled {
  background: rgba(110,124,116,.28);
  box-shadow: none;
  cursor: not-allowed;
}
.hint {
  margin: 2px 0 0;
  color: var(--muted);
  font-size: 11.5px;
  line-height: 1.42;
}

/* ---------- Value meter ---------- */
#value-meter {
  margin-top: 4px;
  padding: 12px 13px;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: rgba(255,255,255,.7);
}
#value-meter[hidden] { display: none; }
.vm-head { display: flex; align-items: baseline; gap: 8px; }
.vm-prod { font-size: 21px; font-weight: 600; color: #16351a; letter-spacing: -.01em; }
.vm-prodsub { font-size: 12px; color: var(--muted); }
.vm-inputs { display: flex; gap: 8px; margin: 10px 0 8px; }
.vm-in { display: flex; align-items: center; gap: 6px; font-size: 12px; color: var(--muted); }
.vm-in input { width: 62px; padding: 6px 8px; border: 1px solid var(--line-2); border-radius: 8px; background: #fff; font: inherit; color: var(--text); }
.vm-track { background: rgba(20,40,30,.08); border-radius: 99px; height: 7px; overflow: hidden; margin-bottom: 8px; }
.vm-track > div { height: 100%; border-radius: 99px; transition: width .15s ease; }
.vm-status { font-size: 12px; line-height: 1.35; }
.vm-money { display: grid; grid-template-columns: repeat(3, 1fr); gap: 7px; margin-top: 9px; }
.vm-money .m { background: rgba(20,40,30,.05); border-radius: 8px; padding: 7px 9px; }
.vm-money .m .k { font-size: 11px; color: var(--muted); }
.vm-money .m .v { font-size: 15px; font-weight: 600; margin-top: 1px; }
.vm-verdict { font-size: 12px; font-weight: 500; margin-top: 9px; padding: 7px 10px; border-radius: 9px; line-height: 1.35; }
.vm-verdict.ok { background: rgba(22,101,52,.10); color: #166534; }
.vm-verdict.bad { background: rgba(168,54,47,.10); color: #a8362f; }
.vm-verdict.neutral { background: rgba(20,40,30,.05); color: var(--muted); }
.vm-ref { font-size: 11px; color: var(--muted); margin-top: 8px; display: flex; align-items: center; gap: 5px; }
.vm-flag { font-size: 11px; margin-top: 7px; display: flex; align-items: flex-start; gap: 5px; line-height: 1.3; }
.vm-flag.neg { color: #a8362f; } .vm-flag.warn { color: #9a6a00; }

/* ---------- Summary ---------- */
#summary {
  display: none;
  padding: 14px 16px;
  border-bottom: 1px solid var(--line);
}
#summary.show { display: block; }
.sum-cards {
  display: flex;
  gap: 8px;
}
.mcard {
  flex: 1;
  padding: 9px 6px;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: rgba(250,247,242,.9);
  text-align: center;
}
.mk {
  color: var(--muted);
  font-size: 11px;
}
.mv {
  margin-top: 2px;
  font-size: 17px;
  font-weight: 600;
}
#sum-gmaps {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  margin-top: 11px;
  color: var(--accent-strong);
  text-decoration: none;
  font-size: 12.5px;
  font-weight: 600;
}
.exp-row {
  display: flex;
  gap: 8px;
  margin-top: 11px;
}
.ghost {
  flex: 1;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  min-height: 34px;
  border: 1px solid var(--line-2);
  border-radius: 11px;
  background: rgba(255,255,255,.76);
  color: #52605a;
  cursor: pointer;
  font-size: 12px;
  font-weight: 600;
}
.ghost:hover { color: var(--accent); border-color: rgba(232,147,46,.45); }
.ghost.danger:hover { color: var(--end); border-color: rgba(224,40,40,.45); }

/* ---------- Controls/list ---------- */
#controls {
  padding: 13px 16px 6px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.search-wrap {
  position: relative;
  display: flex;
  align-items: center;
}
.search-wrap i {
  position: absolute;
  left: 12px;
  color: var(--faint);
  font-size: 17px;
  pointer-events: none;
}
#search {
  width: 100%;
  min-height: 40px;
  padding: 9px 12px 9px 36px;
  border: 1px solid var(--line-2);
  border-radius: 13px;
  background: rgba(255,255,255,.86);
  color: var(--text);
  outline: 0;
  font-size: 13px;
}
#search:focus {
  border-color: rgba(232,147,46,.5);
  box-shadow: 0 0 0 3px rgba(232,147,46,.12);
}
#list-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 9px 16px;
  border-top: 1px solid var(--line);
  border-bottom: 1px solid var(--line);
  color: var(--muted);
  font-size: 12px;
}
#list-head b { color: var(--text); }
.link {
  border: 0;
  background: none;
  color: var(--accent-strong);
  cursor: pointer;
  padding: 0;
  font-size: 12px;
  font-weight: 600;
}
#stop-list {
  flex: 1 1 auto;
  min-height: 0;
  margin: 0;
  padding: 0;
  overflow-y: auto;
  list-style: none;
}
.stop {
  display: grid;
  grid-template-columns: 24px 1fr auto;
  gap: 10px;
  align-items: start;
  padding: 7px 14px;
  border-bottom: 1px solid var(--line);
  cursor: pointer;
  transition: background .12s;
}
.stop:hover { background: rgba(247,244,239,.75); }
.stop.selected { background: rgba(250,236,214,.74); }
.stop.area-selected { background: rgba(249,235,219,.78); }
.stop.selected.area-selected { background: rgba(214,239,255,.82); }
.stop .pick {
  width: 20px;
  height: 20px;
  margin-top: 1px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border: 2px solid rgba(20,45,34,.22);
  border-radius: 6px;
  background: rgba(255,255,255,.82);
  color: #fff;
  font-size: 12px;
}
.stop.selected .pick {
  border-color: var(--accent-blue);
  background: var(--accent-blue);
}
.stop .num {
  width: 23px;
  height: 23px;
  margin-top: 1px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
  background: var(--row-pin-color, #e89a45);
  color: #fff;
  font-size: 12px;
  font-weight: 600;
}
.stop .num.s { background: var(--start); }
.stop .num.f { background: var(--end); }
.stop .body { min-width: 0; }
.stop .addr {
  font-size: 12.5px;
  font-weight: 600;
  line-height: 1.3;
  word-break: break-word;
  text-transform: uppercase;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}
.stop .addr .warn { color: #c77700; }
.stop .sub {
  margin-top: 2px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  color: var(--muted);
  font-size: 11.5px;
}
.stop .tag {
  max-width: 84px;
  padding: 3px 7px;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: rgba(255,255,255,.68);
  color: var(--muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  font-size: 10px;
  font-weight: 600;
}
.stop .tag:empty { display: none; }
.rowacts {
  display: flex;
  gap: 6px;
  margin-top: 8px;
}
.rowacts button {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 4px 8px;
  border: 1px solid var(--line-2);
  border-radius: 8px;
  background: rgba(255,255,255,.82);
  color: var(--muted);
  cursor: pointer;
  font-size: 10.5px;
  font-weight: 600;
}
.rowacts button.on-s { color: var(--start); border-color: rgba(24,182,63,.45); }
.rowacts button.on-f { color: var(--end); border-color: rgba(224,40,40,.45); }
.stop.via-drag { cursor: grab; }
.stop.dragging { opacity: .45; }
.stop.drop-target { box-shadow: inset 0 2px 0 var(--accent-blue); }
.stop .grip { color: var(--faint); font-size: 16px; cursor: grab; margin-top: 2px; }
.stop .rm {
  margin-top: 2px;
  padding: 0;
  border: 0;
  background: none;
  color: var(--faint);
  cursor: pointer;
  font-size: 15px;
}
.stop .rm:hover { color: var(--end); }
.stop .mv {
  margin-top: 2px;
  padding: 0;
  border: 0;
  background: none;
  color: var(--faint);
  cursor: pointer;
  font-size: 16px;
}
.stop .mv:hover { color: var(--accent); }
.stop.routed .rowend { display: flex; align-items: flex-start; gap: 8px; }
.stop.moving { box-shadow: inset 0 0 0 2px var(--accent); border-radius: 8px; }
.stop.moving .mv { color: var(--accent); }
#stop-list.moving-on .stop.routed:not(.moving) { cursor: pointer; background: rgba(232,147,46,.06); }
.move-hint {
  padding: 8px 11px;
  margin: 0 0 8px;
  font-size: 12.5px;
  font-weight: 600;
  color: var(--accent);
  background: rgba(232,147,46,.12);
  border-radius: 8px;
}
.move-endzone {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  margin: 8px 0 2px;
  padding: 12px;
  font-size: 13px;
  font-weight: 600;
  color: var(--accent);
  background: rgba(232,147,46,.08);
  border: 1.5px dashed rgba(232,147,46,.5);
  border-radius: 10px;
  cursor: pointer;
}
.move-endzone:hover { background: rgba(232,147,46,.16); }
.stop.routed { grid-template-columns: 22px 1fr auto; }

/* ---------- Map tools ---------- */
#map-tools {
  position: absolute;
  z-index: 8;
  top: calc(var(--topbar-h) + 28px);
  left: 18px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.map-tool {
  width: 48px;
  height: 48px;
  border: 1px solid rgba(255,255,255,.7);
  border-radius: 14px;
  background: rgba(252,250,246,.97);
  color: #092d1a;
  box-shadow: 0 8px 22px rgba(17,42,31,.15);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 22px;
}
.map-tool:hover,
.map-tool.active {
  background: var(--accent);
  color: #fff;
}
#right-rail {
  position: absolute;
  z-index: 8;
  right: 14px;
  bottom: calc(var(--bottom-nav-h) + 22px);
  width: 62px;
  padding: 6px 4px;
  display: flex;
  flex-direction: column;
  gap: 2px;
  border: 1px solid rgba(0,0,0,.06);
  border-radius: 20px;
  background: #fbf7f1;
  box-shadow: 0 10px 26px rgba(17,42,31,.16);
}
#right-rail button {
  width: 100%;
  min-height: 50px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  border: 0;
  border-radius: 13px;
  background: transparent;
  color: #262626;
  cursor: pointer;
  font-weight: 500;
}
#right-rail i {
  font-size: 23px;
  line-height: 1;
}
#right-rail span {
  font-size: 10.5px;
}
#right-rail button[hidden] { display: none; }
/* Auto-rotas: desktop-only rail button (mobile reaches it via the More menu). */
#right-rail #rail-auto { display: none; }
#right-rail button:hover { color: var(--accent); }
#right-rail button.active {
  color: var(--accent);
  background: rgba(232,147,46,.12);
}
#bottom-nav {
  position: absolute;
  z-index: 8;
  left: 50%;
  bottom: max(24px, calc(env(safe-area-inset-bottom) + 16px));
  transform: translateX(-50%);
  width: min(700px, calc(100vw - 190px));
  height: var(--bottom-nav-h);
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  align-items: center;
  padding: 7px 16px;
  border: 1px solid rgba(255,255,255,.68);
  border-radius: 34px;
  background: rgba(250,248,244,.97);
  box-shadow: 0 14px 38px rgba(17,42,31,.2);
}
#bottom-nav button {
  height: 100%;
  min-width: 0;
  border: 0;
  background: transparent;
  color: #0b2319;
  cursor: pointer;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 3px;
  font-weight: 600;
}
#bottom-nav i {
  font-size: 34px;
  line-height: 1;
}
#bottom-nav span {
  font-size: 13px;
}
#bottom-nav button.active,
#bottom-nav button:hover {
  color: var(--accent-strong);
}
#search-fab {
  position: absolute;
  z-index: 8;
  right: 40px;
  bottom: max(24px, calc(env(safe-area-inset-bottom) + 16px));
  width: 56px;
  height: 56px;
  border: 1px solid rgba(255,255,255,.68);
  border-radius: 50%;
  background: rgba(252,244,233,.97);
  color: #262626;
  box-shadow: 0 10px 26px rgba(17,42,31,.2);
  cursor: pointer;
  font-size: 26px;
}
#search-fab:hover { color: var(--accent); }

/* ---------- Address (geocoding) search ---------- */
#geo-search {
  position: absolute;
  z-index: 13;
  left: 50%;
  top: calc(env(safe-area-inset-top) + var(--topbar-h) + 12px);
  transform: translateX(-50%);
  width: min(620px, calc(100vw - 20px));
}
#geo-search[hidden] { display: none; }
.geo-bar {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 10px 8px 14px;
  border: 1px solid rgba(0,0,0,.06);
  border-radius: 14px;
  background: #fff;
  box-shadow: 0 10px 28px rgba(17,42,31,.18);
}
.geo-bar > i { color: var(--accent); font-size: 20px; }
#geo-input {
  flex: 1;
  min-width: 0;
  border: 0;
  outline: none;
  background: transparent;
  font: inherit;
  font-size: 16px;
  color: var(--text);
}
#geo-close {
  width: 34px; height: 34px;
  flex: 0 0 34px;
  border: 0;
  border-radius: 50%;
  background: rgba(0,0,0,.05);
  color: #555;
  cursor: pointer;
  font-size: 18px;
}
#geo-results {
  list-style: none;
  margin: 6px 0 0;
  padding: 0;
  max-height: 50vh;
  overflow-y: auto;
  border-radius: 14px;
  background: #fff;
  box-shadow: 0 10px 28px rgba(17,42,31,.18);
}
#geo-results:empty { display: none; }
#geo-results li {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px 14px;
  border-bottom: 1px solid var(--line);
  cursor: pointer;
  font-size: 14px;
  color: var(--text);
}
#geo-results li:last-child { border-bottom: 0; }
#geo-results li:hover { background: rgba(232,147,46,.08); }
#geo-results li i { color: var(--accent); font-size: 18px; flex: 0 0 18px; }

/* ---------- Floating optimize button ---------- */
#fab-optimize {
  position: absolute;
  z-index: 9;
  left: 50%;
  transform: translateX(-50%);
  bottom: calc(var(--bottom-nav-h) + 30px);
  display: inline-flex;
  align-items: center;
  gap: 8px;
  height: 46px;
  padding: 0 22px;
  border: 0;
  border-radius: 23px;
  background: var(--accent);
  color: #fff;
  cursor: pointer;
  font-size: 15px;
  font-weight: 600;
  box-shadow: 0 10px 26px rgba(232,147,46,.34);
}
#fab-optimize i { font-size: 20px; }
#fab-optimize:disabled { background: rgba(110,124,116,.55); box-shadow: none; cursor: not-allowed; }
#fab-optimize[hidden] { display: none; }

/* ---------- Route alternatives switcher ---------- */
#route-alts {
  position: absolute;
  z-index: 9;
  left: 50%;
  transform: translateX(-50%);
  bottom: calc(var(--bottom-nav-h) + 26px);
  display: flex;
  align-items: stretch;
  gap: 2px;
  border-radius: 18px;
  overflow: hidden;
  background: rgba(45,118,235,.97);
  color: #fff;
  box-shadow: 0 8px 22px rgba(20,50,90,.34);
}
#route-alts[hidden] { display: none; }
#route-alts button {
  border: 0;
  background: transparent;
  color: #fff;
  cursor: pointer;
  padding: 0 12px;
  font-size: 22px;
  display: flex;
  align-items: center;
}
#route-alts button:hover { background: rgba(255,255,255,.16); }
#route-alts button:disabled { opacity: .35; cursor: default; }
#alt-info { padding: 7px 6px; text-align: center; min-width: 132px; }
#alt-label { font-size: 11px; font-weight: 700; opacity: .9; }
#alt-stats { font-size: 15px; font-weight: 600; line-height: 1.2; }

/* ---------- Pin callout ---------- */
#pin-card {
  position: absolute;
  z-index: 11;
  left: 50%;
  top: calc(var(--topbar-h) + 26px);
  transform: translateX(-50%);
  width: min(880px, calc(100vw - 180px));
  min-height: 72px;
  display: grid;
  grid-template-columns: 238px 1fr 50px;
  align-items: center;
  gap: 16px;
  padding: 10px 14px;
  border: 1px solid rgba(0,0,0,.06);
  border-radius: 12px;
  background: #fff;
  box-shadow: 0 10px 28px rgba(17,42,31,.22);
}
#pin-card[hidden] {
  display: none;
}
.pin-roles {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 6px;
}
.pin-roles button {
  border: 0;
  background: transparent;
  color: #171d1b;
  cursor: pointer;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 3px;
  font-size: 12px;
  font-weight: 600;
}
.check-box {
  width: 34px;
  height: 34px;
  display: flex;
  align-items: center;
  justify-content: center;
  border: 2.5px solid #111;
  border-radius: 8px;
  background: #fff;
}
.pin-roles button.active .check-box {
  background: var(--accent);
  border-color: var(--accent);
}
.pin-roles button.active .check-box::after {
  content: '';
  width: 30%;
  height: 55%;
  margin-top: -12%;
  border-right: 2.5px solid #fff;
  border-bottom: 2.5px solid #fff;
  transform: rotate(42deg);
}
.pin-card-copy {
  min-width: 0;
}
#pin-title {
  display: block;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  font-size: 21px;
  line-height: 1.1;
  font-weight: 600;
  text-transform: uppercase;
}
#pin-eta {
  display: block;
  margin-top: 6px;
  color: #26302d;
  font-size: 15px;
}
#pin-info {
  width: 42px;
  height: 42px;
  border: 0;
  border-radius: 50%;
  background: transparent;
  color: var(--accent);
  cursor: pointer;
  font-size: 30px;
}

/* ---------- Draw and selection overlays ---------- */
#draw-overlay,
#selection-overlay {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
}
#draw-overlay {
  z-index: 7;
  display: none;
}
#draw-overlay.active {
  display: block;
  pointer-events: auto;
  cursor: crosshair;
  touch-action: none;
}
#draw-hit { fill: rgba(255,255,255,.001); }
#draw-path {
  fill: none;
  stroke: rgba(232,147,46,.92);
  stroke-width: 3.5;
  stroke-linejoin: round;
  stroke-linecap: round;
  stroke-dasharray: 2 7;
}
#selection-overlay {
  z-index: 6;
  display: none;
}
#selection-overlay.show { display: block; }
#selection-path {
  fill: rgba(230,235,225,.22);
  stroke: rgba(35,38,38,.72);
  stroke-width: 5;
  stroke-linejoin: round;
}
#selection-bar {
  position: absolute;
  z-index: 11;
  top: calc(var(--topbar-h) + 18px);
  left: 50%;
  transform: translateX(-50%);
  width: min(860px, calc(100% - 32px));
  min-height: 56px;
  display: grid;
  grid-template-columns: 1fr 46px auto;
  align-items: center;
  gap: 12px;
  padding: 8px 12px 8px 22px;
  border: 1px solid rgba(255,255,255,.7);
  border-radius: 28px;
  background: rgba(252,244,233,.96);
  box-shadow: 0 10px 24px rgba(20,60,30,.16);
  color: #111;
  text-align: center;
  font-size: 18px;
  line-height: 1.12;
}
#selection-bar[hidden],
#action-sheet[hidden] {
  display: none;
}
#selection-menu {
  width: 42px;
  height: 42px;
  display: flex;
  align-items: center;
  justify-content: center;
  border: 2px solid rgba(232,147,46,.76);
  border-radius: 50%;
  background: rgba(251,247,241,.86);
  color: var(--accent);
  cursor: pointer;
  font-size: 22px;
}
#selection-cancel {
  min-width: 88px;
  height: 42px;
  border: 0;
  border-radius: 21px;
  background: transparent;
  color: var(--accent);
  cursor: pointer;
  font: inherit;
  font-weight: 600;
}
#action-sheet {
  position: absolute;
  inset: 0;
  z-index: 50;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 86px 24px 24px;
  background: rgba(18,40,27,.44);
}
.sheet-panel {
  width: min(420px, 100%);
  max-height: calc(100% - 20px);
  overflow: auto;
  padding: 18px 18px 14px;
  border: 1px solid rgba(20,32,26,.10);
  border-radius: 20px;
  background: #fff;
  box-shadow: 0 18px 55px rgba(15,55,35,.22);
}
.sheet-panel h2 {
  margin: 2px 2px 16px;
  font-size: 17px;
  line-height: 1.35;
  font-weight: 600;
}
.sheet-panel button {
  width: 100%;
  margin: 0 0 8px;
  padding: 13px 16px;
  border: 0.5px solid rgba(20,32,26,.12);
  border-radius: 11px;
  background: #fff;
  color: var(--text);
  cursor: pointer;
  font: inherit;
  font-size: 15px;
  font-weight: 500;
  text-align: left;
}
.sheet-panel button:hover { background: #f3f4f1; }
.sheet-panel button:last-child { margin-bottom: 0; }
.sheet-panel button.danger { color: #a8362f; border-color: rgba(168,54,47,.28); }
.sheet-panel button.danger:hover { background: rgba(168,54,47,.06); }
#map.adding { cursor: crosshair; }

#route-badge {
  position: absolute;
  left: 50%;
  bottom: 100px;
  transform: translateX(-50%);
  z-index: 9;
  padding: 8px 16px;
  border-radius: 16px;
  background: rgba(45,118,235,.96);
  color: #fff;
  font-size: 14px;
  font-weight: 700;
  line-height: 1.25;
  text-align: center;
  white-space: nowrap;
  box-shadow: 0 6px 18px rgba(20,50,90,.32);
  pointer-events: none;
}
#route-badge[hidden] { display: none; }
.stop .eta { margin-top: 3px; font-size: 11px; font-weight: 600; color: var(--accent); }
.stop .eta.late { color: var(--end); }
.timewin-row { display: flex; align-items: center; gap: 8px; margin: 8px 0 2px; font-size: 13px; font-weight: 600; color: #28332c; cursor: pointer; }
.timewin-row input[type="checkbox"] { width: 16px; height: 16px; accent-color: var(--accent); cursor: pointer; }
.timewin-row input[type="time"] { margin-left: auto; padding: 4px 7px; border: 1px solid rgba(0,0,0,.18); border-radius: 6px; font: inherit; font-size: 12.5px; cursor: pointer; }

/* ---------- More/share sheets ---------- */
.menu-sheet {
  position: absolute;
  inset: 0;
  z-index: 52;
  display: flex;
  align-items: flex-end;
  justify-content: center;
  padding: 22px;
  background: rgba(20,45,30,.4);
}
.menu-sheet[hidden] { display: none; }
.menu-panel {
  position: relative;
  width: min(440px, calc(100vw - 44px));
  max-height: min(80vh, 760px);
  overflow-y: auto;
  padding: 14px 16px 20px;
  border: 1px solid rgba(255,255,255,.72);
  border-radius: 22px;
  background: rgba(255,255,255,1);
  box-shadow: 0 22px 60px rgba(17,42,31,.26);
}
.menu-panel.share {
  align-self: flex-start;
  margin-top: calc(var(--topbar-h) + 70px);
  margin-left: min(24vw, 260px);
}
.menu-panel.tall {
  width: min(460px, calc(100vw - 40px));
}
.grabber {
  position: absolute;
  top: 8px;
  left: 50%;
  width: 44px;
  height: 5px;
  transform: translateX(-50%);
  border-radius: 999px;
  background: rgba(90,100,95,.24);
}
.sheet-close {
  position: absolute;
  top: 11px;
  right: 11px;
  width: 32px;
  height: 32px;
  display: flex;
  align-items: center;
  justify-content: center;
  border: 0;
  border-radius: 50%;
  background: rgba(123,134,128,.14);
  color: #7a8480;
  cursor: pointer;
  font-size: 20px;
}
.sheet-close:hover { background: rgba(123,134,128,.24); }
.menu-group { margin: 2px 0 8px; }
.menu-group-label {
  font-size: 12px;
  font-weight: 600;
  letter-spacing: .02em;
  color: #6e7c74;
  margin: 14px 4px 4px;
}
.menu-group-label:first-child { margin-top: 14px; }
.menu-panel button[data-menu-action] {
  width: 100%;
  display: grid;
  grid-template-columns: 38px 1fr;
  align-items: center;
  gap: 12px;
  padding: 9px 8px;
  border: 0;
  border-radius: 11px;
  background: transparent;
  color: #14201a;
  text-align: left;
  cursor: pointer;
}
.menu-panel button[data-menu-action]:hover { background: rgba(232,147,46,.09); }
.menu-panel button[data-menu-action] i {
  color: var(--accent);
  justify-self: center;
  width: 38px;
  height: 38px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 10px;
  background: rgba(232,147,46,.11);
  font-size: 21px;
  line-height: 1;
}
.menu-panel button[data-menu-action] b {
  display: block;
  font-size: 15px;
  line-height: 1.25;
  font-weight: 600;
}
.menu-panel button[data-menu-action] small {
  display: block;
  margin-top: 2px;
  color: rgba(37,44,42,.58);
  font-size: 12.5px;
  line-height: 1.32;
}
.menu-panel button[disabled] {
  opacity: .42;
  cursor: not-allowed;
}

/* ---------- Magic Clean ---------- */
.magic-title {
  display: flex;
  align-items: center;
  gap: 8px;
  margin: 4px 4px 8px;
  font-size: 26px;
  font-weight: 700;
  color: #1d2622;
}
.magic-title i { color: var(--accent); font-size: 28px; }
.magic-sub {
  margin: 0 4px 14px;
  font-size: 16px;
  line-height: 1.32;
  color: rgba(37,44,42,.66);
}
.magic-list { display: flex; flex-direction: column; gap: 8px; }
.magic-row {
  display: grid;
  grid-template-columns: 30px 1fr auto;
  align-items: center;
  gap: 12px;
  padding: 12px 14px;
  border-radius: 18px;
  background: rgba(137,155,145,.13);
  cursor: pointer;
}
.magic-row input { width: 22px; height: 22px; accent-color: var(--accent); }
.magic-info b { display: block; font-size: 19px; font-weight: 600; line-height: 1.12; color: #0b1110; }
.magic-info small { display: block; margin-top: 3px; font-size: 14px; color: rgba(37,44,42,.6); }
.magic-save {
  text-align: right;
  font-size: 16px;
  font-weight: 700;
  line-height: 1.18;
  color: #c0392b;
  white-space: nowrap;
}
.magic-empty {
  margin: 18px 6px;
  font-size: 18px;
  line-height: 1.4;
  text-align: center;
  color: rgba(37,44,42,.7);
}
.magic-summary {
  margin: 14px 4px 4px;
  font-size: 17px;
  text-align: center;
  color: #1d2622;
}
.magic-summary b { color: var(--accent); }
.magic-actions { display: flex; gap: 12px; margin-top: 16px; }
.magic-btn {
  flex: 1;
  min-height: 56px;
  border: 0;
  border-radius: 18px;
  font-size: 19px;
  font-weight: 700;
  cursor: pointer;
}
.magic-btn.ghost { background: rgba(123,134,128,.18); color: #44504b; }
.magic-btn.primary { background: var(--accent); color: #fff; }
.magic-btn[disabled] { opacity: .45; cursor: not-allowed; }
/* Pulsing highlight on the pins Magic Clean is proposing to remove */
@keyframes magicPulse {
  0%, 100% { box-shadow: 0 0 0 0 rgba(255,49,51,.6); }
  50% { box-shadow: 0 0 0 11px rgba(255,49,51,0); }
}
.marker.magic-flag { z-index: 36 !important; }
.marker.magic-flag .marker-pin {
  border-color: #ff3133 !important;
  animation: magicPulse 1.15s ease-out infinite;
}

/* ---------- Toast ---------- */
#toast {
  position: absolute;
  left: 50%;
  bottom: calc(env(safe-area-inset-bottom) + 110px);
  z-index: 55;
  display: flex;
  align-items: center;
  gap: 16px;
  max-width: min(560px, calc(100vw - 36px));
  padding: 14px 18px;
  transform: translate(-50%, 16px);
  border-radius: 18px;
  background: rgba(28,34,32,.97);
  color: #fff;
  box-shadow: 0 14px 40px rgba(14,24,18,.4);
  opacity: 0;
  pointer-events: none;
  transition: opacity .25s ease, transform .25s ease;
}
#toast.show { opacity: 1; transform: translate(-50%, 0); pointer-events: auto; }
#toast[hidden] { display: none; }
.toast-msg { font-size: 17px; line-height: 1.3; }
.toast-msg b { color: #ffce8f; font-weight: 700; }
.toast-action {
  flex: none;
  padding: 9px 18px;
  border: 0;
  border-radius: 12px;
  background: var(--accent);
  color: #fff;
  font-size: 16px;
  font-weight: 700;
  cursor: pointer;
}

/* ---------- Auto-routes ---------- */
.auto-field { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin: 10px 2px; }
.auto-field label { font-size: 17px; color: #1d2622; font-weight: 600; }
.auto-field input {
  width: 92px;
  padding: 10px 12px;
  border: 1px solid rgba(83,105,91,.28);
  border-radius: 12px;
  background: #fff;
  font-size: 19px;
  font-weight: 700;
  text-align: center;
  color: #0b1110;
}
.auto-info { margin: 6px 2px 14px; font-size: 15px; color: rgba(37,44,42,.66); }
.auto-mode { display: flex; gap: 6px; background: rgba(38,34,30,.06); padding: 4px; border-radius: 12px; }
.auto-mode-btn {
  flex: 1; padding: 9px 10px; border: 0; border-radius: 9px; background: transparent;
  font-size: 14px; font-weight: 700; color: var(--muted); cursor: pointer; white-space: nowrap;
}
.auto-mode-btn.active { background: #fff; color: var(--accent-strong); box-shadow: 0 1px 3px rgba(0,0,0,.12); }
.auto-mode-hint { margin: -2px 2px 12px; font-size: 13.5px; color: rgba(37,44,42,.66); line-height: 1.35; }
.auto-defer-row { opacity: .9; }
.auto-defer-row .auto-route-info small { color: var(--accent-strong); }
.auto-urgent-alert {
  margin: 4px 2px 12px; padding: 9px 12px; border-radius: 10px;
  background: rgba(214,40,40,.10); border: 1px solid rgba(214,40,40,.3);
  color: #b3261e; font-size: 14px; font-weight: 700; line-height: 1.35;
}
#auto-generate { width: 100%; }
.auto-route-row {
  display: grid;
  grid-template-columns: 28px 1fr auto;
  align-items: center;
  gap: 12px;
  padding: 12px 14px;
  margin-bottom: 8px;
  border-radius: 16px;
  background: rgba(137,155,145,.13);
}
.auto-dot { width: 18px; height: 18px; border-radius: 50%; }
.inspopt-row { grid-template-columns: 1fr auto; width: 100%; border: 0; cursor: pointer; font: inherit; text-align: left; color: inherit; }
.inspopt-row:hover { background: rgba(232,147,46,.14); }
#inspopt-list { display: flex; flex-direction: column; gap: 2px; }
.auto-insp { margin-bottom: 12px; }
.auto-insp-head { font-size: 15px; font-weight: 700; color: #1d2622; margin: 2px 2px 8px; }
#auto-insp-list { display: flex; flex-direction: column; gap: 6px; }
.insp-row { display: grid; grid-template-columns: 24px 1fr auto; align-items: center; gap: 10px; padding: 9px 12px; border-radius: 14px; background: rgba(137,155,145,.13); cursor: pointer; }
.insp-row input[type=checkbox] { width: 20px; height: 20px; accent-color: var(--accent); }
.insp-row b { font-size: 17px; color: #0b1110; font-weight: 600; }
.insp-row small { color: rgba(37,44,42,.6); font-size: 13px; margin-left: 6px; }
.insp-del { border: 0; background: transparent; color: rgba(37,44,42,.5); font-size: 18px; cursor: pointer; }
.insp-empty { font-size: 14px; color: rgba(37,44,42,.6); margin: 2px 2px 8px; }
.auto-insp-add { display: grid; grid-template-columns: 1fr 88px auto; gap: 8px; margin-top: 8px; }
.auto-insp-add input { padding: 9px 11px; border: 1px solid rgba(83,105,91,.28); border-radius: 12px; background: #fff; font-size: 16px; }
.auto-route-info b { display: block; font-size: 18px; color: #0b1110; }
.auto-route-info small { display: block; margin-top: 2px; font-size: 14px; color: rgba(37,44,42,.62); }
.auto-open { padding: 9px 16px; border: 0; border-radius: 12px; background: var(--accent); color: #fff; font-size: 15px; font-weight: 700; cursor: pointer; }
.auto-unassigned { margin: 10px 2px 4px; font-size: 15px; color: #c0392b; font-weight: 600; }
.auto-route-info small.auto-warn { color: #c0392b; font-weight: 700; }
#auto-redo { margin-top: 12px; }

/* ---------- Saved pins list ---------- */
.saved-title {
  margin: 4px 4px 10px;
  font-size: 17px;
  font-weight: 600;
  color: var(--text);
}
.saved-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
  overflow-y: auto;
  max-height: 56vh;
}
.saved-empty {
  color: var(--muted);
  font-size: 14px;
  padding: 12px 4px;
}
.saved-row {
  display: flex;
  align-items: stretch;
  gap: 8px;
}
.saved-row .saved-load {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 2px;
  padding: 11px 14px;
  border: 1px solid var(--line-2);
  border-radius: 12px;
  background: var(--surface);
  color: var(--text);
  cursor: pointer;
  text-align: left;
}
.saved-row .saved-load:hover { border-color: var(--accent); }
.saved-row .saved-load b { font-size: 14px; font-weight: 700; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 100%; }
.saved-row .saved-load small { font-size: 12px; color: var(--muted); }
.saved-row .saved-del {
  width: 46px;
  flex: 0 0 46px;
  border: 1px solid var(--line-2);
  border-radius: 12px;
  background: var(--surface);
  color: var(--muted);
  cursor: pointer;
  font-size: 20px;
}
.saved-row .saved-del:hover { color: var(--end); border-color: rgba(224,40,40,.45); }

/* ---------- Inspector home markers (distinct violet, transparent house) ---------- */
.home-marker {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  pointer-events: auto;
  cursor: default;
}
.home-pin {
  width: 30px;
  height: 30px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 9px 9px 9px 3px;
  background: rgba(124, 92, 255, .26);
  border: 2px solid rgba(124, 92, 255, .85);
  color: #5b3fd6;
  font-size: 17px;
}
.home-name {
  max-width: 92px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 10px;
  font-weight: 600;
  color: #4a32b8;
  background: rgba(255, 255, 255, .82);
  padding: 1px 6px;
  border-radius: 6px;
}
#right-rail button.active { color: var(--accent); background: rgba(232,147,46,.12); }

/* ---------- Markers ---------- */
.marker {
  --pin-color: var(--accent-blue);
  width: 28px;
  height: 28px;
  position: absolute;
  border: 0;
  background: transparent;
  padding: 0;
  cursor: pointer;
  pointer-events: auto;
}
.marker-pin {
  position: absolute;
  left: 50%;
  top: 50%;
  width: 21px;
  height: 21px;
  transform: translate(-50%, -60%) rotate(-45deg);
  border: 0;
  border-radius: 50% 50% 50% 2px;
  background: var(--pin-color);
  box-shadow: 0 1px 2px rgba(14, 24, 18, .3);
  transition: width .12s, height .12s, box-shadow .12s, border-width .12s;
}
/* Neon highlight for the WF work codes — same size and color as the pin, but with
   a bright luminous glow (white hot edge + saturated halo in the pin's own color)
   so they really pop. Keeps the base drop shadow underneath. */
.marker.wf-neon .marker-pin {
  box-shadow:
    0 1px 2px rgba(14, 24, 18, .3),
    0 0 0 1px #fff,
    0 0 4px 1px var(--pin-color),
    0 0 9px 3px var(--pin-color);
}
.marker-label {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  transform: rotate(45deg);
  color: #fff;
  font-size: 12px;
  font-weight: 600;
  line-height: 1;
}
/* When a pin has no route number, show a white "house" glyph inside (inRoute-style). */
.marker-label:empty::after {
  content: '';
  width: 11px;
  height: 11px;
  background: center/contain no-repeat url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='%23fff'%3E%3Cpath d='M12 3 3 10v11h6v-6h6v6h6V10z'/%3E%3C/svg%3E");
}
.marker-caption {
  position: absolute;
  left: 50%;
  top: 30px;
  transform: translateX(-50%);
  width: max-content;
  max-width: min(220px, 44vw);
  max-height: 150px;
  display: none;
  padding: 0 2px;
  border: 0;
  background: transparent;
  box-shadow: none;
  white-space: normal;
  overflow: hidden;
  pointer-events: none;
  font-size: 9.5px;
  font-weight: 600;
  line-height: 1.22;
  letter-spacing: .1px;
  text-transform: uppercase;
  text-align: center;
  color: #20303a;
  text-shadow:
    -1px -1px 0 #fff,
    1px -1px 0 #fff,
    -1px 1px 0 #fff,
    1px 1px 0 #fff,
    0 1px 2px rgba(255,255,255,.9);
}
.marker.show-caption .marker-caption {
  display: block;
}
/* Shared-board status: done = faded + green check ring; assigned = faded a touch. */
.marker.ws-done .marker-pin { opacity: .42; }
.marker.ws-done::after {
  content: '✓'; position: absolute; left: 50%; top: 0; transform: translate(-50%, -55%);
  color: #16a34a; font-size: 13px; font-weight: 900; text-shadow: 0 0 2px #fff, 0 0 2px #fff, 0 1px 2px rgba(0,0,0,.3); pointer-events: none;
}
.marker.ws-assigned .marker-pin { opacity: .7; }
.stop.ws-done .addr { opacity: .5; text-decoration: line-through; }
.stop.ws-done::after { content: '✓ feito'; margin-left: auto; color: #16a34a; font-size: 11px; font-weight: 600; }
.stop.ws-assigned .addr { opacity: .75; }
.marker.appt .marker-pin {
  border-radius: 4px;
  transform: translate(-50%, -50%) rotate(45deg);
}
.marker.appt .marker-label { transform: rotate(-45deg); }
/* Appointment caption: wider so the full info fits, and keep the original case
   ("Appt. set 6/22/2026") instead of upper-casing, exactly like inRoute. */
.marker.appt .marker-caption {
  max-width: min(260px, 56vw);
  max-height: 170px;
  text-transform: none;
}
.marker.selected .marker-pin,
.marker.focused .marker-pin {
  width: 25px;
  height: 25px;
  border-width: 2.2px;
  box-shadow: 0 0 0 3px rgba(232,147,46,.18), 0 3px 9px rgba(14,24,18,.36);
}
.marker.area .marker-pin {
  box-shadow: 0 0 0 4px rgba(188,241,170,.78), 0 3px 8px rgba(14,24,18,.38);
}
.marker.routed .marker-pin {
  width: 23px;
  height: 23px;
  border-color: #fff;
  background: var(--pin-color);
}
.marker.routed .marker-label {
  font-size: 11px;
}
/* Neon highlight for Start (green) and End (red) so they're instantly spotted. */
.marker.start .marker-pin {
  width: 26px;
  height: 26px;
  border-color: #fff;
  box-shadow: 0 0 0 3px rgba(22,255,94,.45), 0 0 12px 2px rgba(22,255,94,.9), 0 3px 8px rgba(0,0,0,.35);
}
.marker.end .marker-pin {
  width: 26px;
  height: 26px;
  border-color: #fff;
  box-shadow: 0 0 0 3px rgba(255,17,51,.45), 0 0 12px 2px rgba(255,17,51,.9), 0 3px 8px rgba(0,0,0,.35);
}
.marker.startend .marker-pin {
  box-shadow: 0 0 0 3px rgba(22,255,94,.5), 0 0 12px 2px rgba(255,17,51,.7), 0 3px 8px rgba(0,0,0,.35);
}
/* Appointments stay neon pink as start/end (never green/red). */
.marker.appt.start .marker-pin,
.marker.appt.end .marker-pin,
.marker.appt.startend .marker-pin {
  box-shadow: 0 0 0 3px rgba(255,45,155,.5), 0 0 13px 3px rgba(255,45,155,.95), 0 3px 8px rgba(0,0,0,.35);
}
.mapboxgl-popup-content {
  border-radius: 14px;
  padding: 13px 15px;
  box-shadow: 0 8px 26px rgba(16,24,40,.18);
  font-family: inherit;
  font-size: 13px;
}

/* ---------- Desktop / Mac layout ---------- */
#mac-rail,
#route-mode-bar {
  display: none;
}

@media (min-width: 901px) {
  :root {
    --mac-rail-w: 0px; /* left rail removed on desktop — every button duplicated elsewhere */
    --sidebar-w: 290px;
    --topbar-h: 56px;
  }

  #app {
    background: #eceae6;
  }

  #topbar {
    top: 0;
    left: 0;
    right: 0;
    height: var(--topbar-h);
    padding: 0 16px 0 calc(var(--mac-rail-w) + 12px);
    background: rgba(248,246,242,.98);
    border-bottom: 1px solid rgba(0,0,0,.08);
    box-shadow: none;
    pointer-events: auto;
  }

  #topbar::before {
    content: 'JBA Router Planner';
    position: absolute;
    left: 50%;
    top: 18px;
    transform: translateX(-50%);
    color: rgba(25,28,26,.74);
    font-size: 13px;
    font-weight: 600;
  }

  .brand {
    gap: 10px;
    max-width: min(36vw, 460px);
  }

  .logo {
    width: 34px;
    height: 34px;
    border-radius: 8px;
    font-size: 22px;
    box-shadow: inset 0 1px 0 rgba(255,255,255,.35);
  }

  .bsub {
    max-width: min(32vw, 420px);
    color: rgba(30,38,35,.7);
    font-size: 14px;
    font-weight: 600;
    text-shadow: none;
  }

  .top-right {
    gap: 8px;
  }

  #counts {
    min-height: 28px;
    border: 1px solid rgba(232,147,46,.18);
    border-radius: 7px;
    background: rgba(255,255,255,.52);
    font-size: 12px;
  }

  .round-action {
    width: 34px;
    height: 34px;
    border-radius: 8px;
    box-shadow: none;
    font-size: 20px;
  }

  .go-action {
    min-width: 74px;
    height: 34px;
    border-radius: 17px;
    padding: 0 14px;
    box-shadow: none;
    font-size: 15px;
  }

  .go-action i {
    font-size: 15px;
  }

  #upload-btn {
    min-height: 34px;
    border-radius: 8px;
    box-shadow: none;
    background: rgba(251,247,241,.78);
    font-size: 12px;
  }

  #body {
    top: var(--topbar-h);
  }

  /* Left rail removed on desktop — every button duplicated elsewhere
     (Import in the top bar, Fit in the right rail, Export in the sidebar +
     share menu, Route/Search are the always-open sidebar itself). */
  #mac-rail { display: none; }

  #mac-rail button {
    min-height: 28px;
    border: 0;
    border-radius: 5px;
    background: transparent;
    color: #121515;
    text-align: left;
    cursor: pointer;
    padding: 0 8px;
    font-size: 13px;
    font-weight: 500;
  }

  #mac-rail button.active,
  #mac-rail button:hover {
    background: rgba(185,187,188,.78);
  }

  #sidebar {
    left: var(--mac-rail-w);
    top: 0;
    bottom: 0;
    width: var(--sidebar-w);
    z-index: 10;
    border: 0;
    border-radius: 0;
    border-right: 1px solid rgba(0,0,0,.16);
    background: rgba(242,242,241,.96);
    box-shadow: none;
    transform: none;
    transition: none;
  }

  #route-mode-bar {
    display: grid;
    grid-template-columns: 66px 1fr;
    align-items: center;
    gap: 8px;
    min-height: 38px;
    padding: 0 10px;
    border-bottom: 1px solid rgba(0,0,0,.12);
    background: rgba(246,246,246,.96);
  }

  .edit-mode {
    border: 0;
    background: transparent;
    color: #e8932e;
    cursor: pointer;
    text-align: left;
    font-size: 13px;
    font-weight: 700;
  }

  .mode-tabs {
    height: 32px;
    display: grid;
    grid-template-columns: 1fr;
    border: 1px solid rgba(0,0,0,.1);
    border-radius: 5px;
    overflow: hidden;
    background: #ececef;
  }

  .mode-tabs button {
    border: 0;
    background: transparent;
    cursor: pointer;
    color: #111;
    font-size: 18px;
  }

  .mode-tabs button:last-child {
    border-right: 0;
  }

  .mode-tabs button.active {
    background: #fff;
  }

  #trip {
    padding: 14px 12px;
    border-bottom-color: rgba(0,0,0,.1);
    gap: 8px;
  }

  .sec-label {
    color: #8d908f;
    font-size: 10px;
    letter-spacing: 0;
  }

  .fld {
    min-height: 40px;
    padding: 7px 9px;
    border-radius: 5px;
    background: #fff;
  }

  .seg-btn,
  .btnp,
  .search-wrap #search,
  .mcard,
  .ghost {
    border-radius: 5px;
  }

  .btnp {
    min-height: 34px;
    box-shadow: none;
  }

  .hint {
    display: none;
  }

  #controls {
    padding: 10px 12px 6px;
  }

  #list-head {
    padding: 8px 12px;
    border-color: rgba(0,0,0,.1);
  }

  /* Só rota / Restaurar live in the right rail — drop the sidebar duplicates. */
  #filter-row { display: none; }

  /* Auto-rotas button shows in the rail on desktop (no More menu here). */
  #right-rail #rail-auto { display: flex; }

  .stop { padding: 6px 12px; border-bottom-color: rgba(0,0,0,.08); }
  .stop .addr { font-size: 11.5px; }
  .stop .eta { margin-top: 1px; font-size: 10.5px; }

  #map {
    left: calc(var(--mac-rail-w) + var(--sidebar-w));
    top: 0;
    right: 0;
    bottom: 0;
  }

  #map-canvas .mapboxgl-ctrl-bottom-left,
  #map-canvas .mapboxgl-ctrl-bottom-right {
    transform: none;
  }

  #map-tools {
    top: 14px;
    left: 14px;
    gap: 6px;
  }

  .map-tool {
    width: 34px;
    height: 34px;
    border-radius: 5px;
    box-shadow: 0 1px 3px rgba(0,0,0,.18);
    font-size: 18px;
    background: rgba(255,255,255,.98);
  }

  #right-rail {
    right: 14px;
    bottom: auto;
    top: 122px;
    width: 42px;
    padding: 4px;
    border-radius: 6px;
    background: rgba(255,255,255,.97);
    box-shadow: 0 1px 4px rgba(0,0,0,.22);
  }

  #right-rail button {
    min-height: 41px;
    gap: 1px;
  }

  #right-rail i {
    font-size: 20px;
  }

  #right-rail span {
    font-size: 9px;
    font-weight: 500;
  }

  #bottom-nav,
  #search-fab {
    display: none;
  }

  #pin-card {
    left: 50%;
    bottom: auto;
    top: calc(var(--topbar-h) + 18px);
    width: min(560px, calc(100% - 220px));
    min-height: 52px;
    grid-template-columns: 164px 1fr 32px;
    gap: 10px;
    padding: 6px 8px;
    border-radius: 6px;
    box-shadow: 0 2px 8px rgba(0,0,0,.2);
  }

  .pin-roles {
    gap: 4px;
  }

  .pin-roles button {
    font-size: 9px;
  }

  .check-box {
    width: 28px;
    height: 28px;
    border-width: 2px;
    border-radius: 6px;
  }

  #pin-title {
    font-size: 14px;
  }

  #pin-eta {
    margin-top: 4px;
    font-size: 11px;
  }

  #pin-info {
    width: 28px;
    height: 28px;
    font-size: 20px;
  }

  #selection-bar {
    top: 12px;
    width: min(720px, calc(100% - 90px));
  }

  .menu-panel.share {
    margin-top: 60px;
    margin-left: 0;
  }
}

/* ---------- Mobile ---------- */
@media (max-width: 900px) {
  :root {
    --sidebar-w: min(360px, calc(100vw - 34px));
  }
  /* Mobile already has the search FAB (bottom-right) — hide the rail duplicate. */
  #right-rail #rail-search { display: none; }
  #topbar {
    left: 16px;
    right: 16px;
  }
  .bsub {
    max-width: 40vw;
    font-size: 24px;
  }
  #counts,
  #upload-btn {
    display: none;
  }
  #map-tools {
    left: 18px;
  }
  #bottom-nav {
    width: min(720px, calc(100vw - 116px));
    left: 44px;
    transform: none;
  }
  #pin-card {
    width: calc(100vw - 24px);
    grid-template-columns: 210px 1fr 42px;
    top: calc(env(safe-area-inset-top) + var(--topbar-h) + 14px);
    bottom: auto;
  }
  #pin-title {
    font-size: 18px;
  }
}

@media (max-width: 640px) {
  :root {
    --topbar-h: 58px;
    --bottom-nav-h: 74px;
  }
  #topbar {
    top: max(10px, env(safe-area-inset-top));
    left: 10px;
    right: 10px;
    gap: 8px;
    padding: 0;
  }
  .logo {
    width: 48px;
    height: 48px;
    border-radius: 14px;
    font-size: 28px;
  }
  .bsub {
    max-width: 38vw;
    font-size: 18px;
  }
  .top-right {
    gap: 8px;
  }
  .round-action {
    width: 48px;
    height: 48px;
    font-size: 23px;
  }
  .go-action {
    min-width: 88px;
    height: 48px;
    padding: 0 14px;
    font-size: 20px;
  }
  #clear-map-btn {
    display: none;
  }
  #sidebar {
    top: auto;
    left: 10px;
    right: 10px;
    bottom: calc(var(--bottom-nav-h) + 16px);
    width: auto;
    max-height: 62vh;
    transform: translateY(calc(100% + var(--bottom-nav-h) + 36px));
    border-radius: 25px;
  }
  #sidebar.open {
    transform: translateY(0);
  }
  #map-tools {
    top: calc(var(--topbar-h) + 22px);
    left: 10px;
  }
  .map-tool {
    width: 46px;
    height: 46px;
  }
  #right-rail {
    right: 10px;
    bottom: calc(var(--bottom-nav-h) + 16px);
    width: 60px;
  }
  #right-rail button {
    min-height: 48px;
  }
  #right-rail i {
    font-size: 22px;
  }
  #right-rail span {
    font-size: 10px;
  }
  #bottom-nav {
    left: 10px;
    bottom: max(20px, calc(env(safe-area-inset-bottom) + 14px));
    width: calc(100vw - 84px);
    height: var(--bottom-nav-h);
    padding: 6px 8px;
    border-radius: 28px;
  }
  #bottom-nav i {
    font-size: 28px;
  }
  #bottom-nav span {
    font-size: 11px;
  }
  #search-fab {
    right: 12px;
    bottom: max(29px, calc(env(safe-area-inset-bottom) + 23px));
    width: 54px;
    height: 54px;
    font-size: 24px;
  }
  #pin-card {
    left: 10px;
    right: 10px;
    bottom: auto;
    top: calc(env(safe-area-inset-top) + var(--topbar-h) + 12px);
    transform: none;
    width: auto;
    grid-template-columns: auto 1fr 30px;
    gap: 10px;
    min-height: 54px;
    padding: 7px 10px;
    border-radius: 14px;
  }
  .pin-roles {
    gap: 8px;
  }
  .check-box {
    width: 30px;
    height: 30px;
    border-width: 2px;
    border-radius: 7px;
  }
  .pin-roles button {
    font-size: 10px;
    gap: 2px;
  }
  #pin-title {
    font-size: 14px;
  }
  #pin-eta {
    margin-top: 3px;
    font-size: 12px;
  }
  #pin-info {
    width: 30px;
    height: 30px;
    font-size: 22px;
  }
  #selection-bar {
    top: calc(var(--topbar-h) + 12px);
    grid-template-columns: 1fr 42px auto;
    font-size: 15px;
  }
  .sheet-panel h2 {
    font-size: 16px;
  }
  .sheet-panel button {
    padding: 14px 16px;
    font-size: 15px;
  }
  .menu-sheet {
    padding: 10px;
  }
  .menu-panel,
  .menu-panel.tall,
  .menu-panel.share {
    width: calc(100vw - 20px);
    margin: 0;
    padding: 16px 16px 22px;
    align-self: flex-end;
  }
  /* Slightly bigger touch targets on phones, same compact layout. */
  .menu-panel button[data-menu-action] {
    grid-template-columns: 44px 1fr;
    padding: 11px 8px;
  }
  .menu-panel button[data-menu-action] i {
    width: 44px;
    height: 44px;
    font-size: 23px;
  }
  .menu-panel button[data-menu-action] b {
    font-size: 16px;
  }
  .menu-panel button[data-menu-action] small {
    font-size: 13px;
  }
}
