/* The Run map (runMapView.js), 9 Nov. Uses the dashboard's tokens
   (styles.css :root); Leaflet's own stylesheet is vendor/leaflet/leaflet.css. */

.run-view-toggle { display: inline-flex; border: 1px solid var(--border); border-radius: var(--radius-control); overflow: hidden; background: var(--white); }
.run-view-toggle button {
  min-height: 44px; padding: 0 16px; border: 0; background: transparent; color: var(--muted);
  font: inherit; font-weight: 600; cursor: pointer;
}
.run-view-toggle button + button { border-left: 1px solid var(--border); }
.run-view-toggle button[aria-pressed="true"] { background: var(--dropproof-black); color: var(--white); }
.run-view-toggle button:focus-visible { outline: none; box-shadow: var(--ring-focus); }

.run-map { display: flex; flex-direction: column; gap: 12px; }

/* ---- the bar ---------------------------------------------------------- */
.rm-bar { display: flex; flex-direction: column; gap: 10px; }
.rm-runs { margin: 0; padding: 0; border: 0; min-width: 0; }
.rm-runs-title { padding: 0; margin-bottom: 6px; font-size: var(--fs-label); font-weight: 600; color: var(--muted); }
.rm-run-chips { display: flex; flex-wrap: wrap; gap: 6px; }
.rm-run-chip {
  display: inline-flex; align-items: center; gap: 6px; min-height: 44px; padding: 0 12px;
  border: 1px solid var(--border); border-radius: 999px; background: var(--white);
  font-size: var(--fs-body); font-weight: 600; color: var(--text); cursor: pointer; user-select: none;
}
.rm-run-chip input { width: 16px; height: 16px; margin: 0; accent-color: var(--dropproof-black); }
.rm-run-chip.is-on { border-color: var(--text-strong); }
.rm-run-chip:focus-within { box-shadow: var(--ring-focus); }
.rm-run-loading { font-size: var(--fs-micro); font-weight: 500; color: var(--muted); }
.rm-swatch { display: inline-block; flex: none; width: 12px; height: 12px; border-radius: 50%; background: var(--border); }

.rm-tools { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; }
.rm-fit, .rm-search-btn { min-height: 44px; }
.rm-search-btn { min-width: 56px; }
.rm-search { display: flex; gap: 6px; flex: 1 1 240px; min-width: 0; max-width: 420px; }
.rm-search-input {
  flex: 1; min-width: 0; min-height: 44px; padding: 0 12px; border: 1px solid var(--border);
  border-radius: var(--radius-control); font: inherit; font-size: var(--fs-body); background: var(--white);
}
.rm-search-input:focus { outline: none; box-shadow: var(--ring-focus); border-color: var(--dropproof-teal); }
.rm-search-msg { margin: 0; font-size: var(--fs-label); color: var(--danger-text); }
.rm-toggle { display: inline-flex; align-items: center; gap: 6px; min-height: 44px; padding: 0 4px; font-size: var(--fs-body); font-weight: 600; cursor: pointer; }
.rm-toggle input { width: 16px; height: 16px; margin: 0; accent-color: var(--dropproof-black); }

/* ---- map + side ------------------------------------------------------- */
.rm-body { display: grid; grid-template-columns: minmax(0, 1fr) 280px; gap: 12px; align-items: start; }
.rm-map {
  height: min(70vh, 720px); min-height: 360px; border: 1px solid var(--border);
  border-radius: var(--radius-card); background: #e5e7eb; z-index: 0;
}
.rm-side { display: flex; flex-direction: column; gap: 12px; min-width: 0; }
.rm-side-title { margin: 0 0 8px; font-size: var(--fs-section); font-weight: 700; color: var(--text-strong); }
.rm-legend, .rm-missing-box {
  padding: 12px; border: 1px solid var(--border); border-radius: var(--radius-card); background: var(--white);
}
.rm-legend:empty { display: none; }
.rm-legend ul { margin: 0; padding: 0; list-style: none; display: flex; flex-direction: column; gap: 6px; }
.rm-legend-runs { margin-bottom: 12px !important; }
.rm-legend li { display: flex; align-items: center; gap: 8px; font-size: var(--fs-body); }
.rm-legend-note { margin-left: auto; font-size: var(--fs-micro); color: var(--muted); }
.rm-sample { --run: #475569; position: relative; flex: none; margin: 4px; }
.rm-stop.rm-sample { width: 20px; height: 20px; }
.rm-stop.rm-sample.tone-next { transform: none; width: 20px; height: 20px; margin: 6px 8px 6px 6px; box-shadow: 0 0 0 2px var(--white), 0 0 0 5px var(--run); }
.rm-line-sample { width: 28px; height: 0; border-top: 2px dashed #475569; flex: none; margin: 0 4px; }
.rm-drop-sample { width: 28px; text-align: center; }
.rm-missing-box summary { cursor: pointer; }
.rm-missing-run { display: flex; align-items: center; gap: 6px; margin: 8px 0 4px; font-size: var(--fs-body); font-weight: 700; }
.rm-missing-list { margin: 0 0 0 18px; padding: 0; font-size: var(--fs-body); color: var(--text); }
.rm-missing-list li { padding: 2px 0; overflow-wrap: anywhere; }

/* ---- pins ------------------------------------------------------------- */
/* A pin: one circle per run the customer is on, centred on the customer.
   The R12 tag sits above a circle, the time below it - both outside the
   circle's box, so the circle's centre is the customer's exact point. */
.rm-icon { background: none; border: 0; }
.rm-pin {
  position: absolute; left: 0; top: 0; transform: translate(calc(-50% + var(--dx, 0px)), -50%);
  display: flex; align-items: center; gap: 6px; cursor: pointer;
}
.rm-col { position: relative; display: flex; flex-direction: column; align-items: center; }
.rm-stop {
  position: relative; display: inline-flex; align-items: center; justify-content: center;
  width: 30px; height: 30px; border-radius: 50%; background: var(--run); color: var(--white);
  border: 2px solid var(--white); box-shadow: 0 1px 4px rgba(15, 23, 42, 0.45);
  font-family: Inter, system-ui, sans-serif; font-size: 14px; font-weight: 800; line-height: 1;
}
.rm-num { font-variant-numeric: tabular-nums; }
.rm-stop.is-next, .rm-stop.tone-next {
  width: 38px; height: 38px; font-size: 17px;
  box-shadow: 0 0 0 3px var(--white), 0 0 0 7px var(--run), 0 2px 8px rgba(15, 23, 42, 0.45);
}
/* Delivered: the run's colour, paler - done, still readable - and a tick. */
.rm-stop.tone-delivered { background: color-mix(in srgb, var(--run) 55%, white); }
.rm-badge {
  position: absolute; right: -7px; top: -7px; display: inline-flex; align-items: center; justify-content: center;
  width: 16px; height: 16px; border-radius: 50%; border: 2px solid var(--white);
  font-size: 10px; font-weight: 900; line-height: 1; color: var(--white);
}
.rm-badge-tick { background: #16a34a; }
.rm-badge-ex { background: #d97706; }
.rm-stop.tone-exception { box-shadow: 0 0 0 2px #d97706, 0 1px 4px rgba(15, 23, 42, 0.45); }
/* The ring is the warning, outside a white gap so a red or orange run still
   reads through it: amber due, red overdue or passed. */
.rm-stop.outline-amber { outline: 3px solid #f59e0b; outline-offset: 2px; }
.rm-stop.outline-red { outline: 3px solid #dc2626; outline-offset: 2px; }
.rm-tag {
  position: absolute; bottom: calc(100% + 3px); left: 50%; transform: translateX(-50%);
  padding: 1px 5px; border-radius: 4px; background: var(--white); color: var(--run);
  border: 1.5px solid var(--run); white-space: nowrap;
  font-family: Inter, system-ui, sans-serif; font-size: 10px; font-weight: 800; line-height: 1.2;
}
.rm-time {
  position: absolute; top: calc(100% + 4px); left: 50%; transform: translateX(-50%);
  padding: 1px 5px; border-radius: 4px; background: rgba(255, 255, 255, 0.94); white-space: nowrap;
  font-family: Inter, system-ui, sans-serif; font-size: 11px; font-weight: 700; color: var(--text-strong);
  box-shadow: 0 1px 2px rgba(15, 23, 42, 0.25);
}
.rm-time.is-done { color: #166534; }
.rm-col:has(.is-next) .rm-time { top: calc(100% + 8px); }
.rm-col:has(.is-next) .rm-tag { bottom: calc(100% + 7px); }

/* Pins that truly overlap: a grey rounded rectangle, "3 stops" - no ring
   and no run colour, so it can never be read as a stop. */
.rm-cluster {
  position: absolute; left: 0; top: 0; transform: translate(-50%, -50%);
  display: inline-flex; align-items: center; justify-content: center; height: 26px; padding: 0 9px;
  border-radius: 7px; background: #4b5563; color: var(--white); cursor: pointer; white-space: nowrap;
  box-shadow: 0 1px 4px rgba(15, 23, 42, 0.35);
  font-family: Inter, system-ui, sans-serif; font-size: 12px; font-weight: 700;
}
.rm-cluster.rm-sample { position: relative; transform: none; width: auto; height: 22px; padding: 0 7px; font-size: 11px; }

/* Order lines: dashed, with an arrow per leg - the order, not the road. */
.rm-arrow {
  position: absolute; left: 0; top: 0; width: 0; height: 0; pointer-events: none;
  border-top: 5px solid transparent; border-bottom: 5px solid transparent; border-left: 9px solid var(--run);
  filter: drop-shadow(0 0 1px #fff) drop-shadow(0 0 1px #fff);
}

.rm-drop {
  position: absolute; left: 0; top: 0; transform: translate(22px, -50%);
  display: inline-flex; align-items: center; gap: 4px; padding: 3px 8px 3px 4px; border-radius: 999px;
  background: var(--run); color: var(--white); white-space: nowrap;
  font-size: 11px; font-weight: 700; box-shadow: 0 0 0 2px var(--white), 0 2px 6px rgba(15, 23, 42, 0.35); opacity: 0.92;
}
.rm-drop-van { font-size: 13px; }

/* ---- popup ------------------------------------------------------------ */
.rm-pop { font-family: Inter, system-ui, sans-serif; font-size: var(--fs-body); color: var(--text); }
.rm-pop p { margin: 0; }
.rm-pop-name { font-weight: 700; color: var(--text-strong); margin-bottom: 6px !important; overflow-wrap: anywhere; }
.rm-pop-run + .rm-pop-run { margin-top: 8px; padding-top: 8px; border-top: 1px solid var(--border-subtle); }
.rm-pop-head { display: flex; align-items: center; gap: 6px; font-weight: 600; }
.rm-pop-status { margin-top: 2px !important; }
.rm-pop-time { color: var(--muted); }
.rm-pop-proof { display: inline-block; margin-top: 4px; padding: 8px 0; font-weight: 600; color: var(--action-blue); }

/* ---- phones ----------------------------------------------------------- */
@media (max-width: 760px) {
  .rm-body { grid-template-columns: minmax(0, 1fr); }
  .rm-map { height: 62vh; min-height: 320px; }
  .rm-search { flex-basis: 100%; max-width: none; }
}

/* Leaflet's zoom buttons are 30 px; a thumb needs 44. */
.run-map .leaflet-bar a { width: 44px; height: 44px; line-height: 44px; font-size: 22px; }
.run-map .leaflet-container { font-family: Inter, system-ui, sans-serif; }
