:root {
  --bg: #0b1020;
  --surface: #141a2e;
  --surface-2: #1c2440;
  --line: #27304f;
  --text: #eef2ff;
  --muted: #94a0c4;
  --accent: #22d3a6;
  --accent-ink: #052e24;
  --danger: #f43f5e;
  --radius: 16px;
  --shadow: 0 18px 50px rgba(0, 0, 0, .45);
  --sheet-h: 46vh;

  /* Installed to an iPhone home screen the page runs under the status bar
     and home indicator, so every fixed edge is offset by the safe area. */
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --safe-left: env(safe-area-inset-left, 0px);
  --safe-right: env(safe-area-inset-right, 0px);
}

* { box-sizing: border-box; }

/* An author `display` rule outranks the UA stylesheet's [hidden] rule, so
   elements like .sheet-controls (display:flex) stay visible when the hidden
   property is set. Make hidden actually hide. */
[hidden] { display: none !important; }

html, body {
  margin: 0;
  height: 100%;
  overflow: hidden;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.45 "Segoe UI", system-ui, -apple-system, "Noto Sans Arabic", sans-serif;
  -webkit-text-size-adjust: 100%;
}

#map {
  position: fixed;
  inset: 0;
  bottom: var(--sheet-h);
  z-index: 0;
  background: var(--bg);
}

/* ---------- top bar ---------- */

/* Inverted standard OSM tiles: a dark basemap with no API key. */
.basemap-dark {
  filter: invert(1) hue-rotate(180deg) brightness(.93) contrast(.88) saturate(.75);
}

.topbar {
  position: fixed;
  top: 0;
  inset-inline: 0;
  z-index: 650;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: calc(10px + var(--safe-top)) calc(14px + var(--safe-right)) 10px calc(14px + var(--safe-left));
  background: linear-gradient(180deg, rgba(11, 16, 32, .96), rgba(11, 16, 32, .72) 70%, transparent);
  pointer-events: none;
}

.topbar > * { pointer-events: auto; }

.brand { display: flex; align-items: center; gap: 10px; min-width: 0; }

.brand-mark {
  display: grid;
  place-items: center;
  width: 36px; height: 36px;
  flex: 0 0 36px;
  border-radius: 12px;
  background: var(--accent);
  color: var(--accent-ink);
  font-size: 20px;
  font-weight: 700;
}

.brand-text { min-width: 0; }
.brand-text strong { display: block; font-size: 15px; letter-spacing: .2px; }
.brand-text small { display: block; color: var(--muted); font-size: 11.5px; }

.topbar-actions { display: flex; gap: 8px; }

.icon-btn {
  width: 38px; height: 38px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--surface);
  color: var(--text);
  font-size: 16px;
  cursor: pointer;
  transition: background .15s, transform .1s;
}
.icon-btn:hover { background: var(--surface-2); }
.icon-btn:active { transform: scale(.94); }
.icon-btn.active { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }

/* ---------- search ---------- */

.search-wrap {
  position: fixed;
  top: calc(60px + var(--safe-top));
  inset-inline: 14px;
  z-index: 650;
}

.search-wrap input {
  width: 100%;
  padding: 11px 14px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: rgba(20, 26, 46, .95);
  color: var(--text);
  font-size: 14px;
  box-shadow: var(--shadow);
  backdrop-filter: blur(8px);
}
.search-wrap input::placeholder { color: var(--muted); }
.search-wrap input:focus { outline: 2px solid var(--accent); outline-offset: 0; }

/* ---------- category chips ---------- */

.chips {
  position: fixed;
  top: calc(108px + var(--safe-top));
  inset-inline: 0;
  z-index: 650;
  display: flex;
  gap: 7px;
  padding: 2px 14px 6px;
  overflow-x: auto;
  scrollbar-width: none;
  -webkit-overflow-scrolling: touch;
}
.chips::-webkit-scrollbar { display: none; }

.chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  flex: 0 0 auto;
  padding: 7px 11px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: rgba(20, 26, 46, .95);
  color: var(--text);
  font-size: 12.5px;
  white-space: nowrap;
  cursor: pointer;
  backdrop-filter: blur(8px);
  transition: background .15s, border-color .15s;
}
.chip:hover { background: var(--surface-2); }
.chip .dot { width: 8px; height: 8px; border-radius: 50%; flex: 0 0 8px; }
.chip .n { color: var(--muted); font-variant-numeric: tabular-nums; }
.chip[aria-pressed="true"] {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--accent-ink);
  font-weight: 600;
}
.chip[aria-pressed="true"] .n { color: rgba(5, 46, 36, .7); }

/* ---------- bottom sheet ---------- */

.sheet {
  position: fixed;
  inset-inline: 0;
  bottom: 0;
  z-index: 600;
  height: var(--sheet-h);
  display: flex;
  flex-direction: column;
  background: var(--surface);
  border-top: 1px solid var(--line);
  border-radius: 18px 18px 0 0;
  box-shadow: var(--shadow);
}
/* Animate only when snapping; a live drag must follow the finger exactly. */
.sheet.snapping { transition: height .22s ease-out; }

/* The pinned top of the sheet is the drag handle. touch-action:none stops the
   page from scrolling while it is being dragged. */
.sheet-top { flex: 0 0 auto; touch-action: none; cursor: ns-resize; }
.sheet-top button, .sheet-top select { cursor: pointer; }

.sheet-grip {
  display: block;
  width: 100%;
  padding: 9px 0 7px;
  border: 0;
  background: transparent;
  text-align: center;
  cursor: ns-resize;
}
.sheet-grip span {
  display: inline-block;
  width: 46px; height: 5px;
  border-radius: 99px;
  background: var(--muted);
  opacity: .55;
}

/* Filters and the list scroll together, so the list can take the whole sheet. */
.sheet-body {
  flex: 1 1 auto;
  min-height: 0;
  overflow-y: auto;
  overscroll-behavior: contain;
  -webkit-overflow-scrolling: touch;
  border-top: 1px solid var(--line);
}

/* ---------- visit picks ---------- */

.pick-bar {
  display: flex;
  align-items: center;
  gap: 8px;
  min-height: 34px;   /* fits the buttons, so the list doesn't jump when they appear */
  padding: 0 16px 8px;
  font-size: 12px;
  color: var(--muted);
}
.pick-bar.has-picks .pick-text { color: var(--accent); font-weight: 700; }
.pick-text { flex: 1; min-width: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.pick-btn {
  flex: 0 0 auto;
  padding: 5px 10px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--surface-2);
  color: var(--text);
  font-size: 11.5px;
  font-weight: 600;
}
.pick-btn[aria-pressed="true"] { border-color: var(--accent); color: var(--accent); }

/* ---------- tabs ---------- */

.tabs {
  display: flex;
  gap: 4px;
  padding: 2px 14px 8px;
}
.tab {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 7px 13px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: transparent;
  color: var(--muted);
  font-size: 12.5px;
  font-weight: 600;
  cursor: pointer;
  transition: background .15s, color .15s, border-color .15s;
}
.tab:hover { background: var(--surface-2); color: var(--text); }
.tab[aria-selected="true"] {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--accent-ink);
}
.tab-count {
  font-variant-numeric: tabular-nums;
  opacity: .7;
  font-size: 11px;
}
.tab[hidden] { display: none; }

.cv-row { padding-bottom: 6px; border-bottom: 0; }
.cv-label {
  display: flex;
  align-items: center;
  gap: 8px;
  flex: 1;
  min-width: 0;
  font-size: 12px;
  color: var(--muted);
}
.cv-label select {
  flex: 1;
  min-width: 0;
  padding: 6px 9px;
  border: 1px solid var(--accent);
  border-radius: 9px;
  background: var(--surface-2);
  color: var(--text);
  font-size: 12px;
  font-weight: 600;
}
.cv-hint {
  border-bottom: 0;
  padding-top: 0;
  padding-bottom: 8px;
  font-size: 10.5px;
}

.dir-row { padding-top: 0; }
.dir-label {
  display: flex;
  align-items: center;
  gap: 7px;
  flex: 1;
  min-width: 0;
  font-size: 12px;
  color: var(--muted);
}
.dir-label select {
  flex: 1;
  min-width: 0;
  padding: 5px 8px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface-2);
  color: var(--text);
  font-size: 12px;
}

.dir-note {
  margin: 0;
  padding: 7px 16px;
  border-bottom: 1px solid var(--line);
  color: var(--muted);
  font-size: 11px;
  line-height: 1.4;
}

.row.dir { cursor: default; align-items: flex-start; }
.row.dir:hover { background: transparent; }
.row.dir .row-badge { margin-top: 2px; }
.dir-meta { margin-top: 3px; }
.pill {
  padding: 1px 7px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--surface-2);
  color: var(--muted);
  font-size: 10.5px;
  white-space: nowrap;
}

.mail-btn {
  flex: 0 0 auto;
  align-self: center;
  padding: 6px 11px;
  border: 1px solid var(--line);
  border-radius: 9px;
  background: var(--surface-2);
  color: var(--accent);
  font-size: 11.5px;
  font-weight: 700;
  text-decoration: none;
  white-space: nowrap;
}
.mail-btn:hover { border-color: var(--accent); background: var(--accent); color: var(--accent-ink); }

.empty.more {
  padding: 12px;
  color: var(--muted);
  font-size: 11.5px;
  font-variant-numeric: tabular-nums;
}

.sheet-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 2px 16px 8px;
}
.sheet-head strong { font-size: 17px; }
.sheet-head small { color: var(--muted); font-size: 12px; margin-inline-start: 6px; }

.primary-btn {
  padding: 9px 14px;
  border: 0;
  border-radius: 11px;
  background: var(--accent);
  color: var(--accent-ink);
  font-size: 13px;
  font-weight: 700;
  cursor: pointer;
  white-space: nowrap;
}
.primary-btn:active { transform: scale(.97); }
.primary-btn:disabled { opacity: .5; cursor: not-allowed; }

.sheet-controls {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 0 16px 10px;
  border-bottom: 1px solid var(--line);
}
.radius-label, .stops-label {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 12px;
  color: var(--muted);
}
.radius-label { flex: 1; }
.radius-label output { color: var(--text); font-variant-numeric: tabular-nums; min-width: 46px; }
.radius-label input[type=range] { flex: 1; accent-color: var(--accent); min-width: 60px; }
.stops-label select {
  padding: 5px 8px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface-2);
  color: var(--text);
  font-size: 12px;
}

/* ---------- result rows ---------- */

.results {
  margin: 0;
  padding: 6px 10px 10px;
  list-style: none;
}

.row {
  display: flex;
  align-items: center;
  gap: 11px;
  padding: 10px;
  border-radius: 13px;
  cursor: pointer;
  transition: background .12s;
}
.row:hover { background: var(--surface-2); }
.row.active { background: var(--surface-2); box-shadow: inset 0 0 0 1px var(--accent); }
.row.picked { background: rgba(34, 211, 166, .09); }

/* Tick box at the start of each nearby row. */
.row-check {
  display: grid;
  place-items: center;
  width: 24px; height: 24px;
  flex: 0 0 24px;
  border: 2px solid var(--line);
  border-radius: 7px;
  color: transparent;
  font-size: 14px;
  font-weight: 800;
  transition: background .12s, border-color .12s;
}
.row.picked .row-check {
  border-color: var(--accent);
  background: var(--accent);
  color: var(--accent-ink);
}

/* Route straight to one employer without picking it. */
.row-go {
  display: grid;
  place-items: center;
  width: 34px; height: 34px;
  flex: 0 0 34px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--surface-2);
  color: var(--accent);
  font-size: 14px;
  cursor: pointer;
}
.row-go:hover { border-color: var(--accent); }
html[dir="rtl"] .row-go span { display: inline-block; transform: scaleX(-1); }

.row-badge {
  display: grid;
  place-items: center;
  width: 38px; height: 38px;
  flex: 0 0 38px;
  border-radius: 11px;
  font-size: 17px;
}

.row-main { flex: 1; min-width: 0; }
.row-name {
  font-size: 14px;
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.row-meta {
  display: flex;
  gap: 7px;
  color: var(--muted);
  font-size: 11.5px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.row-cat { color: var(--text); opacity: .75; }

.isic-code {
  flex: 0 0 auto;
  padding: 1px 5px;
  border: 1px solid var(--line);
  border-radius: 5px;
  background: var(--surface-2);
  color: var(--accent);
  font: 600 10.5px/1.5 ui-monospace, "Cascadia Mono", Consolas, monospace;
  font-variant-numeric: tabular-nums;
}

.isic-row { padding-top: 0; }
.isic-label {
  display: flex;
  align-items: center;
  gap: 8px;
  flex: 1;
  min-width: 0;
  font-size: 12px;
  color: var(--muted);
}
.isic-label select {
  flex: 1;
  min-width: 0;
  padding: 5px 8px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface-2);
  color: var(--text);
  font-size: 12px;
}

.popup-registry {
  margin: 7px 0;
  padding: 7px 8px;
  border-radius: 8px;
  background: var(--surface-2);
}
.popup-registry em {
  display: block;
  margin-bottom: 5px;
  color: var(--muted);
  font-size: 10px;
  font-style: normal;
  text-transform: uppercase;
  letter-spacing: .4px;
}
.popup-registry > div {
  display: flex;
  gap: 7px;
  align-items: baseline;
  margin-top: 3px;
  font-size: 11.5px;
}
.popup-registry > div > span:first-child {
  flex: 0 0 auto;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
}
.popup-registry > div > span:last-child { color: var(--text); }

.row-dist { text-align: end; flex: 0 0 auto; }
.row-dist b { display: block; font-size: 14px; font-variant-numeric: tabular-nums; }
.row-dist small { color: var(--muted); font-size: 10.5px; }

.empty { padding: 28px 16px; text-align: center; color: var(--muted); font-size: 13.5px; }

.attribution {
  padding: 7px 16px calc(7px + var(--safe-bottom));
  border-top: 1px solid var(--line);
  color: var(--muted);
  font-size: 10.5px;
  text-align: center;
}

/* ---------- route card ---------- */

.route-card {
  position: fixed;
  z-index: 700;
  inset-inline: 14px;
  bottom: calc(var(--sheet-h) + 12px);
  max-width: 420px;
  margin-inline: auto;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: rgba(20, 26, 46, .97);
  box-shadow: var(--shadow);
  backdrop-filter: blur(10px);
  animation: rise .18s ease-out;
}

@keyframes rise { from { opacity: 0; transform: translateY(10px); } }

.route-close {
  position: absolute;
  top: 8px; inset-inline-end: 8px;
  width: 28px; height: 28px;
  border: 0;
  border-radius: 8px;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
  font-size: 13px;
}
.route-close:hover { background: var(--surface-2); color: var(--text); }

.route-head { display: flex; align-items: center; gap: 10px; padding-inline-end: 30px; }
.route-icon { font-size: 22px; }
.route-head-text { min-width: 0; }
.route-head-text strong {
  display: block;
  font-size: 15px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.route-head-text small { color: var(--muted); font-size: 11.5px; }

.route-metrics {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
  margin: 12px 0 10px;
}
.route-metrics > div {
  padding: 9px 6px;
  border-radius: 11px;
  background: var(--surface-2);
  text-align: center;
}
.route-metrics span {
  display: block;
  font-size: 15px;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}
.route-metrics label { display: block; color: var(--muted); font-size: 10px; margin-top: 2px; }

.route-stops { margin-bottom: 10px; max-height: 136px; overflow-y: auto; }
.route-stop {
  display: flex;
  align-items: center;
  gap: 9px;
  padding: 5px 2px;
  font-size: 12.5px;
}
.route-stop i {
  display: grid;
  place-items: center;
  width: 20px; height: 20px;
  flex: 0 0 20px;
  border-radius: 50%;
  background: var(--accent);
  color: var(--accent-ink);
  font-size: 10.5px;
  font-style: normal;
  font-weight: 700;
}
.route-stop span { flex: 1; min-width: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.route-stop em { color: var(--muted); font-size: 11px; font-style: normal; }

.route-steps { border-top: 1px solid var(--line); padding-top: 8px; }
.route-steps summary {
  cursor: pointer;
  color: var(--muted);
  font-size: 12px;
  list-style: none;
}
.route-steps summary::-webkit-details-marker { display: none; }
.route-steps summary::before { content: "▸ "; }
.route-steps[open] summary::before { content: "▾ "; }
.route-steps ol {
  max-height: 150px;
  margin: 8px 0 0;
  padding-inline-start: 20px;
  overflow-y: auto;
  color: var(--text);
  font-size: 12.5px;
}
.route-steps li { margin-bottom: 5px; }
.route-steps li em { color: var(--muted); font-style: normal; }

.route-foot { display: flex; gap: 8px; margin-top: 10px; }
.ghost-btn {
  flex: 1;
  padding: 9px;
  border: 1px solid var(--line);
  border-radius: 11px;
  background: var(--surface-2);
  color: var(--text);
  font-size: 12.5px;
  font-weight: 600;
  text-align: center;
  text-decoration: none;
  cursor: pointer;
}
.ghost-btn:hover { border-color: var(--accent); color: var(--accent); }

/* ---------- map pins ---------- */

.pin {
  width: 26px; height: 26px;
  display: grid;
  place-items: center;
  border: 2px solid rgba(255, 255, 255, .85);
  border-radius: 50% 50% 50% 4px;
  transform: rotate(-45deg);
  box-shadow: 0 3px 8px rgba(0, 0, 0, .5);
  font-size: 11px;
}
.pin > span { transform: rotate(45deg); }
.pin.picked {
  width: 30px; height: 30px;
  border: 3px solid var(--accent);
  box-shadow: 0 0 0 4px rgba(34, 211, 166, .3), 0 3px 8px rgba(0, 0, 0, .5);
  font-size: 13px;
  font-weight: 800;
}

.me-dot {
  width: 18px; height: 18px;
  border: 3px solid #fff;
  border-radius: 50%;
  background: #2f80ff;
  box-shadow: 0 0 0 7px rgba(47, 128, 255, .25), 0 2px 7px rgba(0, 0, 0, .5);
}

.marker-cluster {
  background: rgba(34, 211, 166, .28);
  border-radius: 50%;
}
.marker-cluster div {
  width: 32px; height: 32px;
  margin-top: 4px; margin-inline-start: 4px;
  display: grid;
  place-items: center;
  border-radius: 50%;
  background: var(--accent);
  color: var(--accent-ink);
  font: 700 12px/1 "Segoe UI", system-ui, sans-serif;
}

.leaflet-popup-content-wrapper {
  border-radius: 12px;
  background: var(--surface);
  color: var(--text);
  box-shadow: var(--shadow);
}
.leaflet-popup-tip { background: var(--surface); }
.leaflet-popup-content { margin: 11px 13px; font-size: 13px; }
.leaflet-popup-content b { display: block; margin-bottom: 3px; }
.leaflet-popup-content i { color: var(--muted); font-size: 11.5px; font-style: normal; }
.leaflet-popup-content button {
  margin-top: 8px;
  padding: 6px 10px;
  border: 0;
  border-radius: 8px;
  background: var(--accent);
  color: var(--accent-ink);
  font-size: 12px;
  font-weight: 700;
  cursor: pointer;
}
.popup-actions { display: flex; flex-wrap: wrap; gap: 6px; }
.leaflet-popup-content .popup-actions button { margin-top: 8px; }
.leaflet-popup-content button.secondary {
  background: var(--surface-2);
  color: var(--text);
  box-shadow: inset 0 0 0 1px var(--line);
}
.leaflet-popup-close-button { color: var(--muted) !important; }
.leaflet-container { background: var(--bg); font-family: inherit; }
.leaflet-bar a { background: var(--surface); color: var(--text); border-color: var(--line); }
.leaflet-bar a:hover { background: var(--surface-2); color: var(--text); }
.leaflet-control-attribution {
  background: rgba(11, 16, 32, .8) !important;
  color: var(--muted) !important;
  font-size: 9.5px !important;
}
.leaflet-control-attribution a { color: var(--muted) !important; }

/* ---------- toast + loader ---------- */

.toast {
  position: fixed;
  bottom: calc(var(--sheet-h) + 18px);
  inset-inline: 0;
  z-index: 900;
  width: fit-content;
  max-width: 86vw;
  margin-inline: auto;
  padding: 10px 16px;
  border-radius: 999px;
  background: #222b47;
  color: var(--text);
  font-size: 13px;
  box-shadow: var(--shadow);
  animation: rise .18s ease-out;
}
.toast.err { background: var(--danger); color: #fff; }

.loader {
  position: fixed;
  inset: 0;
  z-index: 1000;
  display: grid;
  place-content: center;
  justify-items: center;
  gap: 16px;
  background: var(--bg);
  color: var(--muted);
  font-size: 13.5px;
  transition: opacity .3s;
}
.loader.gone { opacity: 0; pointer-events: none; }
.spinner {
  width: 34px; height: 34px;
  border: 3px solid var(--line);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin .8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- RTL + responsive ---------- */

html[dir="rtl"] .pin { border-radius: 50% 50% 4px 50%; transform: rotate(45deg); }
html[dir="rtl"] .pin > span { transform: rotate(-45deg); }
html[dir="rtl"] .route-steps summary::before { content: "◂ "; }
html[dir="rtl"] .route-steps[open] summary::before { content: "▾ "; }

@media (min-width: 820px) {
  :root { --sheet-h: 100vh; }
  #map { inset-inline-start: 400px; bottom: 0; }
  .sheet {
    inset-inline: auto 0;
    inset-inline-start: 0;
    width: 400px;
    height: 100vh;
    border-radius: 0;
    border-top: 0;
    border-inline-end: 1px solid var(--line);
    padding-top: calc(148px + var(--safe-top));
  }
  .sheet-grip { display: none; }
  .sheet-top { cursor: default; touch-action: auto; }
  .topbar, .search-wrap, .chips { inset-inline: 0 auto; width: 400px; }
  .route-card { inset-inline: auto 16px; bottom: 16px; width: 380px; }
  .toast { inset-inline: 400px 0; bottom: 24px; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
}
