/* app.css — MyField styles complementing Tailwind.
 *
 * Layout: #map is a full-screen fixed underlay; #drawer slides in from the
 * left (docked open on md+); #topbar is a floating status pill.
 * body[data-mode="pins|route"] shows/hides view-specific controls.
 */

html, body { margin: 0; height: 100%; }

#map {
  position: fixed;
  inset: 0;
  z-index: 0;
  height: 100%;
  width: 100%;
}

#topbar {
  top: calc(env(safe-area-inset-top) + 10px);
  max-width: calc(100vw - 140px);
  white-space: nowrap;
}

/* ---- View switching ------------------------------------------------------- */
body[data-mode="pins"] .route-only { display: none !important; }
body[data-mode="route"] .pins-only { display: none !important; }

/* Section tabs in the drawer header: icon only, the active one shows its name. */
.tab {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  height: 40px;
  min-width: 40px;
  padding: 0 10px;
  border-radius: 6px;
  font-size: 14px;
  font-weight: 600;
  white-space: nowrap;
  -webkit-touch-callout: none; /* long-press shows OUR tooltip, not the iOS callout */
  -webkit-user-select: none;
  user-select: none;
  touch-action: manipulation;
}
.tab svg { width: 20px; height: 20px; flex-shrink: 0; }
.tab .tab-label { display: none; }
.tab.seg-active .tab-label { display: inline; }

/* Long-press / hover name tooltip for icon-only buttons. */
.tip {
  position: fixed;
  z-index: 950;
  padding: 4px 8px;
  font-size: 12px;
  font-weight: 600;
  color: #fff;
  background: #1e293b;
  border-radius: 6px;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.25);
  pointer-events: none;
  white-space: nowrap;
}
.tip[hidden] { display: none; }

/* The map pill names the section (MyFieldService/TheSearch). On the narrowest
   phones the counts move out and the text shrinks so the name always fits
   between the corner buttons. The drawer brand stacks as "MyField / Service"
   so the active tab keeps its name next to it (the header is only ~294px). */
@media (max-width: 359px) {
  #topbar .topbar-stats { display: none !important; }
  #topbar { font-size: 12px; }
  .brand { font-size: 14px; line-height: 1.05; }
  .brand-svc { display: block; }
}

/* Name colouring: "My", "The", "Way" in the brand green; "Service" in blue
   (the icon's arrow colour; a lighter blue on the dark map pill). The rest of each word keeps the
   surrounding text colour (dark in the drawer, white on the pill). */
.name-accent { color: #22c55e; }
.name-svc { color: #2563eb; }
#topbar .name-svc { color: #60a5fa; }
.tab.seg-active .tab-label { color: #0f172a; }

.seg button { background: transparent; color: #475569; }
.seg button.seg-active {
  background: #fff;
  color: #15803d;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.15);
}

/* ---- Left slide-out drawer ------------------------------------------------ */
#drawer {
  transform: translateX(-100%);
  transition: transform 0.3s ease;
  will-change: transform;
}
#drawer.open { transform: translateX(0); }

#menuBtn.hidden { display: none !important; }

/* ---- Markers -------------------------------------------------------------- */
.wf-pin__dot {
  width: 26px;
  height: 26px;
  border-radius: 50%;
  color: #fff;
  font-size: 12px;
  font-weight: 700;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 1px 5px rgba(0, 0, 0, 0.45);
  border: 2px solid #fff;
}

.wf-here { position: relative; }
/* "You are here": TheSearch's person badge, centred in a 52px box so the
   direction arrow (.wf-here__rot) can orbit it. */
.wf-here__dot {
  position: absolute;
  left: 10px;
  top: 10px;
  width: 32px;
  height: 32px;
  border-radius: 50%;
  background: #3b82f6;
  border: 3px solid #fff;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.3);
  display: flex;
  align-items: center;
  justify-content: center;
}
.wf-here__dot svg { width: 18px; height: 18px; fill: #fff; }

/* ---- Map controls --------------------------------------------------------- */
.maplibregl-ctrl-group button {
  width: 40px !important;
  height: 40px !important;
  line-height: 40px !important;
  font-size: 20px !important;
}

.map-btn {
  width: 40px;
  height: 40px;
  border-radius: 9999px;
  background: rgba(30, 41, 59, 0.95);
  color: #fff;
  font-size: 18px;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.35);
  display: flex;
  align-items: center;
  justify-content: center;
  border: 2px solid transparent;
}
.map-btn:active { transform: scale(0.95); }
.map-btn.map-btn-on { border-color: #22c55e; background: #166534; }

/* ---- Lists, tabs, modals -------------------------------------------------- */
.sortable-ghost { opacity: 0.4; }

[data-tab] { background: #f1f5f9; color: #475569; border-color: #e2e8f0; }
[data-tab].tab-active { background: #15803d; color: #fff; border-color: #15803d; }

.pin-cat-btn {
  width: 40px;
  height: 40px;
  padding: 0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: 10px;
  background: #f1f5f9;
  border: 2px solid #e2e8f0;
  touch-action: manipulation;
}
.pin-cat-btn.cat-active { border-color: #16a34a; background: #dcfce7; }

.modal-overlay {
  display: none;
  position: fixed;
  inset: 0;
  align-items: center;
  justify-content: center;
  padding: 10px;
  background: rgba(0, 0, 0, 0.45);
}
.modal-card {
  background: #fff;
  width: 100%;
  border-radius: 12px;
  overflow: hidden;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.25);
}
.modal-head {
  background: #15803d;
  color: #fff;
  padding: 7px 12px;
  font-weight: 700;
  font-size: 13.5px;
}

:focus-visible { outline: 2px solid #16a34a; outline-offset: 2px; }

@media (prefers-reduced-motion: reduce) {
  #drawer { transition: none; }
}

/* ---- Desktop: dock the drawer as a permanent left panel ------------------- */
@media (min-width: 768px) {
  #drawer {
    width: 24rem;
    max-width: 24rem;
    transform: none !important;
    border-right: 1px solid #e2e8f0;
    transition: none;
  }
  #map { left: 24rem; }
  #menuBtn, #drawerClose, #drawerBackdrop { display: none !important; }
  #topbar {
    left: auto;
    right: 16px;
    transform: none;
    top: 16px;
    max-width: none;
  }
  /* The map's top-right controls sit under the pill on desktop. */
  .maplibregl-ctrl-top-right { margin-top: 56px; }
}

/* ---- PWA install banner: never cover modals, the drawer or map buttons ---- */
.pwa-install-banner { z-index: 550 !important; }
body:has(.pwa-install-show) #mapBtns { bottom: calc(env(safe-area-inset-bottom) + 112px); }

/* Direction-of-travel arrow: rotates around the dot; hidden when stationary */
.wf-here__rot { position: absolute; inset: 0; transition: transform 0.25s linear; }
.wf-here__rot[hidden] { display: none; }
.wf-here__arrow {
  position: absolute;
  left: 17px;
  top: -4px;
  width: 0;
  height: 0;
  border-left: 9px solid transparent;
  border-right: 9px solid transparent;
  border-bottom: 18px solid #2563eb;
  filter: drop-shadow(0 1px 2px rgba(0, 0, 0, 0.5));
}
@media (prefers-reduced-motion: reduce) { .wf-here__rot { transition: none; } }

.pin-cat-btn .cat-emoji { font-size: 20px; line-height: 1; }
.pin-cat-btn .cat-text { font-size: 12px; font-weight: 700; color: #334155; }

/* ---- Route line: hidden while zooming, fades back in when zoom stops ------ */

/* ---- Map data credits (required by OpenStreetMap, OpenFreeMap and Esri) ------ */
.maplibregl-ctrl-attrib {
  margin: 0 0 6px 6px !important;
  padding: 1px 6px !important;
  max-width: calc(100vw - 70px); /* stay clear of the floating map buttons */
  font-size: 11px !important;
  line-height: 1.4;
  color: #334155 !important;
  background: rgba(255, 255, 255, 0.85) !important;
  border-radius: 4px;
}
.maplibregl-ctrl-attrib a { color: #15803d !important; }

/* Street / Hybrid chooser */
.mf-layers { position: relative; }
.mf-layers-toggle { display: flex !important; align-items: center; justify-content: center; color: #334155; }
.mf-layers-menu {
  position: absolute;
  right: 0;
  top: calc(100% + 4px);
  display: flex;
  flex-direction: column;
  min-width: 112px;
  padding: 4px;
  background: #fff;
  border-radius: 8px;
  box-shadow: 0 2px 10px rgba(0, 0, 0, 0.25);
}
.mf-layers-menu[hidden] { display: none; }
.mf-layers-menu button {
  width: auto !important;
  height: 40px !important;
  padding: 0 12px !important;
  text-align: left;
  font-size: 14px;
  font-weight: 600;
  color: #334155;
  border-radius: 6px;
}
.mf-layers-menu button[aria-checked="true"] { color: #15803d; background: #dcfce7; }

/* Pins and the you-are-here badge are DOM markers above the map canvas. */
.wf-pin { cursor: grab; }
.wf-here { pointer-events: none; width: 52px; height: 52px; }

/* ---- Google Maps attribution (required when the Google map is shown) ------ */
.gm-attribution {
  margin: 0 0 6px 6px !important;
  clear: both;
  padding: 2px 8px;
  max-width: calc(100vw - 80px);
  font-size: 12px;
  line-height: 1.35;
  color: #334155;
  background: rgba(255, 255, 255, 0.92);
  border-radius: 6px;
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.25);
  pointer-events: auto;
}
.gm-attribution .gm-name { font-weight: 700; color: #1e293b; margin-right: 6px; }
@media (min-width: 768px) { .gm-attribution { max-width: 60vw; } }

/* WayFinder: visited stops. The pin's colour is inline, hence !important. */
.wf-pin--visited .wf-pin__dot { background: #94a3b8 !important; opacity: 0.85; }
.stop-visited .stop-title { text-decoration: line-through; color: #64748b; }
.stop-visited { opacity: 0.7; }
.visit-box { width: 40px; height: 40px; }
.visit-box input { width: 20px; height: 20px; accent-color: #16a34a; cursor: pointer; }
/* Colour of the leg that leaves this stop (matches its line on the map). */
.stop-leg { border-left: 4px solid var(--leg, transparent); }
