/* ============================================================
   Route Board — dispatch console
   Palette is deliberately "petrol + signal": deep blue-green ink,
   a working teal for actions, amber for what is still outstanding.
   ============================================================ */

:root {
  --ink:        #10222f;
  --ink-2:      #1d384a;
  --paper:      #f4f6f5;
  --surface:    #ffffff;
  --line:       #dce3e6;
  --line-soft:  #eaeef0;
  --muted:      #5f7280;

  --teal:       #0f7a72;
  --teal-dark:  #0a5d57;
  --amber:      #b96411;
  --green:      #2f7d4f;
  --waze:       #33ccff;

  --radius:     6px;
  --shadow:     0 6px 24px rgba(16, 34, 47, .14);

  --display:    "Archivo", "Helvetica Neue", sans-serif;
  --body:       "IBM Plex Sans", system-ui, sans-serif;
  --mono:       "IBM Plex Mono", ui-monospace, monospace;
}

* { box-sizing: border-box; }

html, body {
  height: 100%;
  margin: 0;
  /* belt-and-suspenders: nothing should ever be able to force a horizontal
     scrollbar, even if a descendant's content is wider than expected */
  overflow-x: hidden;
}

body {
  font-family: var(--body);
  font-size: 14px;
  color: var(--ink);
  background: var(--paper);
  display: flex;
  flex-direction: column;
}

.mono { font-family: var(--mono); font-variant-numeric: tabular-nums; }

.sr-only {
  position: absolute;
  width: 1px; height: 1px;
  padding: 0; margin: -1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
}

:focus-visible {
  outline: 2px solid var(--teal);
  outline-offset: 2px;
}

/* ---------- top bar ---------- */

.topbar {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  gap: 20px;
  height: 56px;
  padding: 0 18px;
  background: var(--ink);
  color: #e8eef1;
}

.brand {
  display: flex;
  align-items: center;
  gap: 9px;
}

.brand__mark {
  width: 12px;
  height: 12px;
  border: 2px solid var(--waze);
  border-radius: 50%;
  box-shadow: 0 0 0 3px rgba(51, 204, 255, .18);
}

.brand__name {
  font-family: var(--display);
  font-weight: 700;
  font-size: 16px;
  letter-spacing: .04em;
  text-transform: uppercase;
}

.topbar__route {
  margin: 0;
  font-size: 12.5px;
  color: #9fb3bd;
  letter-spacing: .02em;
}

.topbar__route .mono { color: #d6e2e7; }

.topbar .btn {
  margin-left: auto;
}

/* ---------- location status banner ---------- */

.locate-status {
  flex: 0 0 auto;
  margin: 0;
  padding: 10px 18px;
  font-size: 13px;
  font-weight: 500;
  line-height: 1.4;
}

.locate-status[hidden] { display: none; }

.locate-status--ok {
  background: #e6f2ea;
  color: var(--green);
}

.locate-status--error {
  background: #fdece2;
  color: var(--amber);
}

/* ---------- buttons ---------- */

.btn {
  font-family: var(--body);
  font-size: 13px;
  font-weight: 600;
  line-height: 1;
  padding: 11px 14px;
  min-height: 40px;
  border-radius: var(--radius);
  border: 1px solid transparent;
  cursor: pointer;
  touch-action: manipulation;
  text-decoration: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  transition: background-color .15s ease, color .15s ease, border-color .15s ease;
}

.btn--solid {
  background: var(--teal);
  color: #fff;
}
.btn--solid:hover { background: var(--teal-dark); }

.btn--ghost {
  background: transparent;
  border-color: currentColor;
  color: inherit;
  opacity: .85;
}
.btn--ghost:hover { opacity: 1; }

.btn--waze {
  background: var(--waze);
  color: #06283a;
}
.btn--waze:hover { background: #21b9ec; }

.btn.is-busy { opacity: .6; pointer-events: none; }

/* ---------- shell ---------- */

.shell {
  flex: 1 1 auto;
  display: grid;
  /* minmax(0, 1fr), not bare 1fr — a plain 1fr track still won't shrink
     below its content's natural width, so one long unbroken string (an
     address, a hint) can silently force the whole grid wider than the
     viewport. minmax(0, ...) is what actually lets it shrink and wrap. */
  grid-template-columns: 356px minmax(0, 1fr);
  min-height: 0;
}

/* ---------- left panel ---------- */

.panel {
  background: var(--surface);
  border-right: 1px solid var(--line);
  display: flex;
  flex-direction: column;
  min-height: 0;
  min-width: 0;
}

.stats {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  margin: 0;
  border-bottom: 1px solid var(--line);
}

.stat {
  padding: 14px 16px;
}
.stat + .stat { border-left: 1px solid var(--line-soft); }

.stat dt {
  font-size: 10.5px;
  letter-spacing: .1em;
  text-transform: uppercase;
  color: var(--muted);
}

.stat dd {
  margin: 4px 0 0;
  font-size: 22px;
  font-weight: 500;
}

.stat--done    { color: var(--green); }
.stat--pending { color: var(--amber); }

.search {
  display: flex;
  gap: 8px;
  padding: 14px 16px 10px;
}

.search input[type="search"] {
  flex: 1 1 auto;
  min-width: 0;
  font-family: var(--body);
  /* 16px stops iOS Safari auto-zooming the page when this gets focus */
  font-size: 16px;
  padding: 11px 11px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--paper);
  color: var(--ink);
}

.search input[type="search"]::placeholder { color: #93a4ae; }

.filters {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  padding: 0 16px 12px;
  border-bottom: 1px solid var(--line);
}

.chip {
  font-size: 12px;
  font-weight: 500;
  padding: 8px 12px;
  min-height: 32px;
  display: inline-flex;
  align-items: center;
  border-radius: 999px;
  border: 1px solid var(--line);
  color: var(--muted);
  text-decoration: none;
  touch-action: manipulation;
}
.chip:hover { border-color: var(--teal); color: var(--teal); }

.chip--on {
  background: var(--ink);
  border-color: var(--ink);
  color: #fff;
}

/* ---------- form error banner ---------- */

.form-error {
  margin: 0 16px 10px;
  padding: 9px 12px;
  font-size: 12.5px;
  background: #fdece2;
  color: var(--amber);
  border: 1px solid #f4cba3;
  border-radius: var(--radius);
}

/* ---------- panel hint ---------- */

.panel-hint {
  margin: 0;
  padding: 0 16px 12px;
  font-size: 12px;
  line-height: 1.5;
  color: var(--muted);
  border-bottom: 1px solid var(--line);
}

/* ---------- inline stop edit form ---------- */

.stop-edit {
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: 12px 16px;
  background: #fbfbf9;
}

.stop-edit input[type="text"],
.stop-edit input[type="number"],
.stop-edit select {
  font-family: var(--body);
  font-size: 16px;
  padding: 10px 10px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--ink);
  width: 100%;
}

.stop-edit__row {
  display: grid;
  grid-template-columns: 1fr 1fr 1fr;
  gap: 8px;
}

.stop-edit__actions {
  display: flex;
  gap: 8px;
}

/* ---------- per-stop action row (edit / toggle / delete) ---------- */

.stop__actions {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
  padding: 0 10px 8px 48px;
  margin-top: -6px;
}

.stop__action-form {
  display: contents;
}

.stop__action {
  font-family: var(--body);
  font-size: 12.5px;
  font-weight: 500;
  color: var(--muted);
  background: none;
  border: 0;
  padding: 8px 8px;
  min-height: 36px;
  cursor: pointer;
  text-decoration: underline;
  text-underline-offset: 2px;
  touch-action: manipulation;
}

.stop__action:hover { color: var(--teal); }

.stop__action--danger:hover { color: #c0392b; }

/* ---------- the stop list: a route spine ---------- */

.stops {
  list-style: none;
  margin: 0;
  padding: 8px 0 24px;
  overflow-y: auto;
  overflow-x: hidden;
  flex: 1 1 auto;
  min-width: 0;
}

.stop {
  position: relative;
}

/* the vertical line linking one stop to the next — this is the route */
.stop::before {
  content: "";
  position: absolute;
  left: 31px;
  top: 30px;
  bottom: -6px;
  width: 1px;
  background: var(--line);
}
.stop:last-child::before { display: none; }

.stop__hit {
  display: flex;
  gap: 12px;
  width: 100%;
  padding: 14px 16px;
  min-height: 44px;
  background: none;
  border: 0;
  border-left: 3px solid transparent;
  font: inherit;
  color: inherit;
  text-align: left;
  cursor: pointer;
  touch-action: manipulation;
}

.stop__hit:hover { background: var(--paper); }

.stop.is-active .stop__hit {
  background: #eef5f4;
  border-left-color: var(--teal);
}

.stop__seq {
  flex: 0 0 auto;
  width: 28px;
  height: 28px;
  display: grid;
  place-items: center;
  border-radius: 50%;
  background: var(--surface);
  border: 1px solid var(--line);
  font-size: 12px;
  font-weight: 500;
  color: var(--muted);
  z-index: 1;
}

.stop[data-status="done"] .stop__seq {
  background: var(--green);
  border-color: var(--green);
  color: #fff;
}

.stop.is-active .stop__seq {
  background: var(--teal);
  border-color: var(--teal);
  color: #fff;
}

.stop__body {
  display: block;
  min-width: 0;
}

.stop__name {
  display: block;
  font-weight: 600;
  font-size: 13.5px;
}

.stop__address {
  display: block;
  margin-top: 2px;
  font-size: 12px;
  color: var(--muted);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.stop__meta {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-top: 7px;
}

.stop__distance {
  font-size: 11.5px;
  color: var(--muted);
}

.tag {
  font-size: 10px;
  letter-spacing: .08em;
  text-transform: uppercase;
  padding: 3px 7px;
  border-radius: 3px;
}

.tag--pending { background: #fdf0e2; color: var(--amber); }
.tag--done    { background: #e6f2ea; color: var(--green); }

.stops__empty {
  padding: 28px 16px;
  color: var(--muted);
  font-size: 13px;
}

/* ---------- map ---------- */

.map-area {
  position: relative;
  min-height: 0;
  min-width: 0;
}

#map {
  position: absolute;
  inset: 0;
  background: var(--paper);
}

/* numbered pins, drawn with CSS so they match the list exactly */
.pin {
  display: grid;
  place-items: center;
  width: 30px;
  height: 30px;
  border-radius: 50% 50% 50% 2px;
  transform: rotate(-45deg);
  background: var(--amber);
  border: 2px solid #fff;
  box-shadow: 0 2px 6px rgba(16, 34, 47, .35);
}

.pin span {
  transform: rotate(45deg);
  font-family: var(--mono);
  font-size: 12px;
  font-weight: 500;
  color: #fff;
}

.pin--done   { background: var(--green); }
.pin--active { background: var(--teal); width: 36px; height: 36px; }
.pin--active span { font-size: 14px; }

.pin--me {
  border-radius: 50%;
  transform: none;
  width: 18px;
  height: 18px;
  background: var(--waze);
  border: 3px solid #fff;
}

/* ---------- global place search (any location, like Google Maps / Waze) ---------- */

.place-search {
  position: absolute;
  top: 16px;
  left: 16px;
  width: 340px;
  max-width: calc(100% - 32px);
  z-index: 600;
}

.place-search__input {
  width: 100%;
  font-family: var(--body);
  /* 16px stops iOS Safari auto-zooming the page when this gets focus */
  font-size: 16px;
  padding: 13px 40px 13px 14px;
  min-height: 44px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--ink);
  box-shadow: var(--shadow);
}

.place-search__input::placeholder { color: #93a4ae; }

.place-search__clear {
  position: absolute;
  top: 50%;
  right: 4px;
  transform: translateY(-50%);
  width: 36px;
  height: 36px;
  border: 0;
  border-radius: 50%;
  background: none;
  font-size: 18px;
  line-height: 1;
  color: var(--muted);
  cursor: pointer;
  touch-action: manipulation;
}
.place-search__clear:hover { background: var(--paper); }

.place-search__results {
  list-style: none;
  margin: 6px 0 0;
  padding: 6px 0;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  max-height: 320px;
  overflow-y: auto;
}

.place-search__results[hidden] { display: none; }

.place-result {
  display: block;
  width: 100%;
  padding: 11px 14px;
  min-height: 44px;
  border: 0;
  background: none;
  text-align: left;
  font-family: var(--body);
  cursor: pointer;
  touch-action: manipulation;
}

.place-result:hover,
.place-result.is-focused {
  background: var(--paper);
}

.place-result__name {
  display: block;
  font-size: 13px;
  font-weight: 600;
  color: var(--ink);
}

.place-result__address {
  display: block;
  margin-top: 2px;
  font-size: 11.5px;
  color: var(--muted);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.place-result--empty,
.place-result--status {
  padding: 10px 14px;
  font-size: 12.5px;
  color: var(--muted);
  cursor: default;
}

/* the searched-place pin, distinct from route stops */
.pin--search {
  background: var(--ink-2);
}

/* ---------- navigation card ---------- */

.nav-card {
  position: absolute;
  left: 16px;
  bottom: 16px;
  width: 320px;
  max-width: calc(100% - 32px);
  padding: 18px;
  background: var(--surface);
  border-radius: 8px;
  box-shadow: var(--shadow);
  z-index: 500;
}

.nav-card[hidden] { display: none; }

.nav-card__close {
  position: absolute;
  top: 8px; right: 10px;
  border: 0;
  background: none;
  font-size: 20px;
  line-height: 1;
  color: var(--muted);
  cursor: pointer;
}

.nav-card__eyebrow {
  margin: 0;
  font-size: 10.5px;
  letter-spacing: .14em;
  text-transform: uppercase;
  color: var(--teal);
}

.nav-card__title {
  font-family: var(--display);
  font-weight: 600;
  font-size: 19px;
  line-height: 1.2;
  margin: 6px 0 4px;
}

.nav-card__address {
  margin: 0;
  font-size: 12.5px;
  color: var(--muted);
}

.nav-card__coords {
  margin: 8px 0 0;
  font-size: 11.5px;
  color: var(--ink-2);
  padding-top: 8px;
  border-top: 1px solid var(--line-soft);
}

.nav-card__actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 14px;
}

.nav-card__actions .btn--ghost {
  color: var(--muted);
  border-color: var(--line);
}

.place-save {
  display: block;
  width: 100%;
  margin-top: 10px;
}

.place-save.is-saved {
  background: var(--green);
  pointer-events: none;
}

.nav-card__hint {
  margin: 12px 0 0;
  font-size: 11.5px;
  line-height: 1.45;
  color: var(--muted);
}

/* ---------- narrow screens (phones, small tablets) ---------- */

@media (max-width: 860px) {
  .shell {
    grid-template-columns: minmax(0, 1fr);
    grid-template-rows: 46vh 1fr;
  }
  .panel { border-right: 0; border-bottom: 1px solid var(--line); }

  .topbar { flex-wrap: wrap; height: auto; padding: 10px 14px; gap: 10px 14px; }
  .topbar__route { width: 100%; order: 3; }
  .topbar .btn { margin-left: 0; }

  /* leave clearance so it never overlaps the Leaflet zoom buttons */
  .place-search { right: 52px; width: auto; }

  .nav-card,
  #placeCard {
    left: 12px;
    right: 12px;
    bottom: 12px;
    width: auto;
    /* leave clearance at the top for .place-search (~60px tall) so a tall
       card scrolls internally instead of growing up over the search box */
    max-height: calc(100% - 88px);
    overflow-y: auto;
  }

  .stat dd { font-size: 19px; }

  .stop__actions { padding-left: 44px; }
}

@media (max-width: 480px) {
  .brand__name { font-size: 14px; }
  .topbar__route { font-size: 11.5px; }
  .stats { grid-template-columns: repeat(3, 1fr); }
  .nav-card__title { font-size: 17px; }
}

@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; animation: none !important; }
}
