:root {
  --primary: #3B5BF6;
  --primary-dark: #2741C7;
  --primary-soft: #EEF2FF;
  --ink: #111827;
  --ink-2: #374151;
  --muted: #6B7280;
  --line: #E5E7EB;
  --card: #FFFFFF;
  --dark: #262F3D;
  --dark-2: #323C4C;
  --street: #8FB0FF;
  --green: #16A34A;
  --radius: 16px;
  --shadow: 0 8px 28px rgba(15, 23, 42, 0.12), 0 1px 3px rgba(15, 23, 42, 0.08);
  --font: "IBM Plex Sans Arabic", system-ui, -apple-system, "Segoe UI", Tahoma, sans-serif;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; overflow: hidden; background: #EDEFF2; color: var(--ink); font-family: var(--font); }
button { font: inherit; color: inherit; border: 0; background: none; cursor: pointer; padding: 0; }
[hidden] { display: none !important; }
svg { display: block; flex: none; }

#app { position: fixed; inset: 0; }
#map { position: absolute; inset: 0; width: 100%; height: 100%; touch-action: none; display: block; cursor: grab; }
#map:active { cursor: grabbing; }

/* ---------- search ---------- */
.topbar { position: absolute; top: calc(12px + var(--safe-top)); inset-inline: 12px; z-index: 5; max-width: 420px; }
.search {
  display: flex; align-items: center; gap: 10px; height: 52px; padding: 0 14px;
  background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow);
}
.search-icon { color: var(--muted); }
.search input {
  flex: 1; min-width: 0; height: 100%; border: 0; outline: 0; background: none;
  font: 500 15.5px var(--font); color: var(--ink);
}
.search input::placeholder { color: #9CA3AF; }
.search input::-webkit-search-cancel-button { display: none; }
.icon-btn { width: 34px; height: 34px; border-radius: 50%; display: grid; place-items: center; color: var(--muted); }
.icon-btn:hover { background: #F3F4F6; }

.results {
  list-style: none; margin: 8px 0 0; padding: 6px; background: var(--card); border-radius: var(--radius);
  box-shadow: var(--shadow); max-height: min(60vh, 440px); overflow: auto;
}
.results li { display: flex; align-items: center; gap: 12px; padding: 10px; border-radius: 12px; cursor: pointer; }
.results li:hover, .results li.active { background: #F5F7FF; }
.results .r-icon { width: 38px; height: 38px; border-radius: 12px; display: grid; place-items: center; background: var(--primary-soft); color: var(--primary); flex: none; }
.results .r-name { font-weight: 600; font-size: 15px; }
.results .r-sub { font-size: 12.5px; color: var(--muted); margin-top: 1px; }
.results .empty { color: var(--muted); font-size: 14px; justify-content: center; cursor: default; }

/* ---------- floating buttons ---------- */
.fabs { position: absolute; inset-inline-start: 12px; bottom: calc(24px + var(--safe-bottom)); z-index: 4; display: flex; flex-direction: column; gap: 10px; transition: bottom .25s; }
.fab {
  width: 46px; height: 46px; border-radius: 14px; background: var(--card); box-shadow: var(--shadow);
  display: grid; place-items: center; color: var(--ink-2);
}
.fab:active { transform: scale(.96); }
.fab.active { color: var(--primary); }
.desktop-only { display: none; }

.hint {
  position: absolute; top: calc(76px + var(--safe-top)); left: 50%; transform: translateX(-50%); z-index: 6;
  background: var(--dark); color: #fff; padding: 10px 16px; border-radius: 12px; font-size: 14px; font-weight: 500;
  box-shadow: var(--shadow); white-space: nowrap;
}

.toast {
  position: absolute; left: 50%; transform: translateX(-50%); bottom: calc(30px + var(--safe-bottom)); z-index: 20;
  background: var(--dark); color: #fff; padding: 11px 16px; border-radius: 12px; font-size: 14px; max-width: calc(100% - 32px);
  box-shadow: var(--shadow); text-align: center;
}

/* ---------- bottom sheet ---------- */
.sheet {
  position: absolute; inset-inline: 0; bottom: 0; z-index: 6; background: var(--card);
  border-radius: 22px 22px 0 0; box-shadow: 0 -6px 30px rgba(15, 23, 42, 0.12);
  padding: 6px 16px calc(16px + var(--safe-bottom)); max-height: 72vh; overflow: auto;
  animation: up .22s ease-out;
}
@keyframes up { from { transform: translateY(30px); opacity: 0; } }
.grabber { width: 40px; height: 5px; border-radius: 3px; background: #E5E7EB; margin: 4px auto 10px; }

.sheet-head { display: flex; align-items: center; gap: 12px; }
.place-icon { width: 46px; height: 46px; border-radius: 14px; display: grid; place-items: center; background: #F3F4F6; color: var(--ink-2); flex: none; }
.sheet-title { flex: 1; min-width: 0; }
.sheet-title h2 { margin: 0; font-size: 18px; font-weight: 700; line-height: 1.35; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.sheet-title p { margin: 2px 0 0; color: var(--muted); font-size: 13.5px; display: flex; gap: 6px; align-items: center; flex-wrap: wrap; }
.phone { color: var(--primary); text-decoration: none; font-weight: 500; }
.dot-sep { width: 3px; height: 3px; border-radius: 50%; background: #9CA3AF; }
.round-btn { width: 40px; height: 40px; border-radius: 50%; border: 1px solid var(--line); display: grid; place-items: center; color: var(--ink-2); flex: none; background: #fff; }
.round-btn:hover { background: #F9FAFB; }

.actions { display: flex; gap: 10px; margin-top: 16px; }
.btn {
  height: 48px; border-radius: 12px; padding: 0 18px; display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  font-weight: 600; font-size: 15px; transition: background .15s, transform .1s;
}
.btn:active { transform: scale(.98); }
.btn.primary { background: var(--primary); color: #fff; flex: 1; }
.btn.primary:hover { background: #3350E8; }
.btn.ghost { border: 1px solid var(--line); color: var(--ink-2); background: #fff; }
.btn.ghost:hover { background: #F9FAFB; }
.btn.soft { background: var(--primary-soft); color: var(--primary); }

/* route sheet */
.route-ends { position: relative; border: 1px solid var(--line); border-radius: 14px; padding: 4px 12px; padding-inline-end: 56px; }
.route-end { display: flex; align-items: center; gap: 12px; padding: 9px 0; }
.route-end + .route-end { border-top: 1px solid var(--line); }
.route-end small { display: block; color: var(--muted); font-size: 12px; }
.route-end b { display: block; font-weight: 600; font-size: 14.5px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 62vw; }
.end-dot { width: 12px; height: 12px; border-radius: 50%; flex: none; }
.end-dot.start { border: 3px solid var(--primary); background: #fff; }
.end-dot.dest { background: var(--primary); box-shadow: 0 0 0 3px var(--primary-soft); }
.route-ends .round-btn { position: absolute; inset-inline-end: 8px; top: 50%; transform: translateY(-50%); }

.summary { display: flex; align-items: flex-end; justify-content: space-between; gap: 12px; margin-top: 14px; }
.summary .dur { font-size: 24px; font-weight: 700; color: var(--green); line-height: 1.2; }
.summary .dist { font-size: 15px; color: var(--muted); font-weight: 500; }
.summary p { margin: 2px 0 0; color: var(--muted); font-size: 13.5px; }
.summary .eta { text-align: end; font-size: 13px; color: var(--muted); }
.summary .eta b { display: block; color: var(--ink); font-size: 16px; }

.steps { list-style: none; margin: 14px 0 0; padding: 0; border-top: 1px solid var(--line); }
.steps li { display: flex; align-items: center; gap: 12px; padding: 10px 2px; border-bottom: 1px solid #F3F4F6; }
.steps .s-icon { width: 36px; height: 36px; border-radius: 10px; background: #F3F4F6; display: grid; place-items: center; color: var(--ink-2); flex: none; }
.steps .s-text { flex: 1; font-size: 14px; font-weight: 500; }
.steps .s-dist { color: var(--muted); font-size: 13px; white-space: nowrap; }

/* route options */
.options { display: flex; flex-direction: column; gap: 8px; margin-top: 12px; }
.opt { text-align: start; border: 1.5px solid var(--line); border-radius: 14px; padding: 10px 14px; background: #fff; width: 100%; }
.opt.sel { border-color: var(--primary); background: #F7F9FF; }
.opt-top { display: flex; align-items: baseline; gap: 6px; flex-wrap: wrap; }
.opt .dur { font-size: 20px; font-weight: 700; color: var(--green); }
.opt .dur.slow { color: var(--ink); }
.opt .dist { color: var(--muted); font-size: 14px; }
.opt p { margin: 2px 0 0; color: var(--muted); font-size: 13px; }
.badge { margin-inline-start: auto; font-size: 12px; font-weight: 600; padding: 2px 8px; border-radius: 20px; background: #DCFCE7; color: #15803D; }
.badge.muted { background: #F3F4F6; color: var(--muted); }

/* ---------- navigation ---------- */
.nav-banner {
  position: absolute; top: calc(10px + var(--safe-top)); inset-inline: 10px; z-index: 7; max-width: 460px;
  background: var(--dark); color: #fff; border-radius: 18px; box-shadow: var(--shadow); overflow: hidden;
}
.nav-main { display: flex; align-items: center; gap: 14px; padding: 16px 18px; }
.nav-arrow { width: 56px; height: 56px; border-radius: 14px; background: var(--dark-2); display: grid; place-items: center; flex: none; }
.nav-dist { font-size: 15px; font-weight: 600; opacity: .9; }
.nav-street { font-size: 21px; font-weight: 700; color: var(--street); line-height: 1.3; margin-top: 2px; }
.nav-then { display: flex; align-items: center; gap: 8px; padding: 9px 18px; background: var(--dark-2); font-size: 13.5px; color: #D1D5DB; }

.nav-card { display: flex; align-items: center; gap: 12px; }
.nav-card .center { flex: 1; text-align: center; min-width: 0; }
.nav-card .center b { font-size: 17px; font-weight: 700; }
.nav-card .center b span { color: var(--muted); font-weight: 500; font-size: 15px; }
.nav-card .center p { margin: 3px 0 0; color: var(--muted); font-size: 13.5px; display: flex; align-items: center; justify-content: center; gap: 6px; }
.nav-card .center p span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.speed {
  position: absolute; inset-inline-end: 14px; bottom: calc(130px + var(--safe-bottom)); z-index: 5;
  width: 58px; height: 58px; border-radius: 50%; background: var(--dark); color: #fff; box-shadow: var(--shadow);
  display: flex; flex-direction: column; align-items: center; justify-content: center; line-height: 1.05;
}
.speed b { font-size: 19px; }
.speed small { font-size: 10px; opacity: .8; }
.recenter {
  position: absolute; left: 50%; transform: translateX(-50%); bottom: calc(130px + var(--safe-bottom)); z-index: 5;
  display: inline-flex; gap: 8px; align-items: center; background: var(--card); color: var(--primary); font-weight: 600;
  padding: 10px 16px; border-radius: 22px; box-shadow: var(--shadow); font-size: 14px;
}
.mode-nav .topbar, .mode-nav #btnLocate, .mode-nav .desktop-only { display: none; }
.mode-pick .topbar { display: none; }

/* ---------- desktop ---------- */
@media (min-width: 820px) {
  .desktop-only { display: grid; }
  .sheet {
    inset-inline: auto; inset-inline-start: 12px; top: 76px; bottom: auto; width: 400px;
    border-radius: var(--radius); max-height: calc(100vh - 100px); box-shadow: var(--shadow);
    padding: 16px; animation: none;
  }
  .grabber { display: none; }
  .route-end b { max-width: 260px; }
  .fabs { inset-inline-start: auto; inset-inline-end: 16px; bottom: 24px !important; }
  .mode-nav .sheet { top: auto; bottom: 16px; }
  .speed { inset-inline-end: auto; inset-inline-start: 430px; bottom: 24px; }
  .recenter { bottom: 28px; }
}
