/* Square Ibis — live driver map, arrival estimates, ratings (v2.2)
   1 map component · 2 markers · 3 live map page · 4 arrival estimate card · 5 ratings · 6 driver app */

/* ---------- 1. map component (components/map.js) ---------- */

.map {
  position: relative;
  overflow: hidden;
  min-height: 220px;
  border-radius: var(--r-lg);
  border: 1px solid var(--border);
  background: var(--surface-2);
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
  cursor: grab;
  outline: none;
  isolation: isolate;
}
.map:focus-visible { box-shadow: 0 0 0 2px var(--accent); }
.map.is-dragging { cursor: grabbing; }
.map.is-static { touch-action: auto; cursor: default; }
/* tiles and markers are placed with physical pixel offsets (the map itself does not mirror in Arabic) */
.map-tiles, .map-markers { position: absolute; inset: 0; }
.map-tile { position: absolute; left: 0; top: 0; width: 256px; height: 256px; max-width: none; opacity: 0; transition: opacity .25s; will-change: transform; pointer-events: none; }
.map-tile.is-loaded { opacity: 1; }
.map-tile.is-error { visibility: hidden; }
:root[data-theme="dark"] .map-tile { filter: brightness(.66) contrast(1.1) saturate(.7); }
.map.is-tileless { background: repeating-linear-gradient(45deg, var(--surface), var(--surface) 12px, var(--surface-2) 12px, var(--surface-2) 24px); }
.map-lines { position: absolute; left: 0; top: 0; pointer-events: none; overflow: visible; }
.map-line { fill: none; stroke-linecap: round; stroke-linejoin: round; }
.map-line.trail { stroke: var(--accent); stroke-width: 4; opacity: .85; }
.map-line.route { stroke: var(--text-3); stroke-width: 2.5; stroke-dasharray: 6 7; opacity: .8; }
.map-marker { position: absolute; left: 0; top: 0; z-index: 1; will-change: transform; }
.map-marker-in { transform: translate(-50%, -50%); }
.map-marker.is-pin .map-marker-in { transform: translate(-50%, -100%); }
.map-marker.is-click { cursor: pointer; }
.map-marker.is-click:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; border-radius: 50%; }
.map-ctl { position: absolute; top: 10px; inset-inline-end: 10px; z-index: 10; display: flex; flex-direction: column; border-radius: 12px; overflow: hidden; border: 1px solid var(--border-strong); background: var(--panel-solid); box-shadow: var(--shadow-sm); }
.map-zoom-btn { width: 34px; height: 34px; display: grid; place-items: center; color: var(--text); }
.map-zoom-btn + .map-zoom-btn { border-top: 1px solid var(--border); }
.map-zoom-btn:hover { background: var(--surface-2); }
.map-zoom-btn svg { width: 16px; height: 16px; }
.map-attr { position: absolute; bottom: 0; inset-inline-end: 0; z-index: 10; padding: 2px 7px; font-size: 10.5px; border-start-start-radius: 8px; background: color-mix(in srgb, var(--panel-solid) 82%, transparent); color: var(--text-2); }
.map-attr a { color: inherit; }

/* ---------- 2. markers ---------- */

.map-drv {
  --c: var(--gray);
  position: relative;
  width: 36px;
  height: 36px;
  display: grid;
  place-items: center;
  border-radius: 50%;
  background: var(--panel-solid);
  border: 3px solid var(--c);
  box-shadow: 0 6px 16px -6px rgba(0, 0, 0, .55);
  color: var(--text);
  font-size: 12px;
  font-weight: 700;
  letter-spacing: .02em;
  transition: transform .2s var(--ease);
}
.map-drv svg { width: 18px; height: 18px; color: var(--c); }
.map-drv.live { --c: var(--green); }
.map-drv.live::after { content: ""; position: absolute; inset: -7px; border-radius: 50%; border: 2px solid var(--c); opacity: 0; animation: mapPulse 2s ease-out infinite; }
.map-drv.recent { --c: var(--amber); }
.map-drv.stale, .map-drv.none { --c: var(--gray); opacity: .8; }
.map-drv.is-focus { transform: scale(1.18); box-shadow: 0 0 0 4px color-mix(in srgb, var(--accent) 35%, transparent), 0 8px 20px -6px rgba(0, 0, 0, .6); }
.map-drv-dir { position: absolute; inset: -10px; transform: rotate(var(--deg)); pointer-events: none; }
.map-drv-dir::before { content: ""; position: absolute; top: 0; left: 50%; margin-left: -5px; border: 5px solid transparent; border-bottom: 7px solid var(--c); border-top: 0; }
@keyframes mapPulse { 0% { transform: scale(.7); opacity: .8; } 100% { transform: scale(1.35); opacity: 0; } }
.map-stop { position: relative; width: 26px; height: 26px; display: grid; place-items: center; border-radius: 50% 50% 50% 0; transform: rotate(-45deg); background: var(--grad); box-shadow: 0 4px 12px -4px rgba(0, 0, 0, .5); }
.map-stop b { transform: rotate(45deg); color: var(--on-accent, #fff); font-size: 11.5px; font-family: var(--mono); }
.map-point { width: 20px; height: 20px; display: grid; place-items: center; border-radius: 50%; border: 2px solid var(--panel-solid); color: #fff; box-shadow: 0 3px 8px -3px rgba(0, 0, 0, .5); }
.map-point svg { width: 12px; height: 12px; stroke-width: 3; }
.map-point.ok { background: var(--green); }
.map-point.bad { background: var(--rose); }
.map-dest { width: 32px; height: 32px; display: grid; place-items: center; border-radius: 50% 50% 50% 0; transform: rotate(-45deg); background: var(--rose); box-shadow: 0 6px 14px -6px rgba(0, 0, 0, .6); }
.map-dest svg { transform: rotate(45deg); width: 16px; height: 16px; color: #fff; }

/* ---------- 3. live map page (/app/map) ---------- */

.lm-page { max-width: none; }
.lm-banner:empty { display: none; }
.lm-layout { display: grid; grid-template-columns: minmax(0, 1fr) 340px; gap: 14px; align-items: stretch; min-height: 0; }
.lm-map-wrap { min-width: 0; }
.lm-map { height: max(460px, calc(100vh - 230px)); height: max(460px, calc(100dvh - 230px)); }
.lm-side { display: flex; flex-direction: column; gap: 12px; min-width: 0; max-height: max(460px, calc(100vh - 230px)); overflow-y: auto; }
.lm-list { display: flex; flex-direction: column; gap: 6px; }
.lm-item { display: flex; align-items: center; gap: 10px; width: 100%; padding: 9px 10px; border-radius: 13px; border: 1px solid var(--border); background: var(--surface); text-align: start; color: var(--text); transition: background .15s, border-color .15s; }
.lm-item:hover { background: var(--surface-2); }
.lm-item.is-active { border-color: var(--accent); background: color-mix(in srgb, var(--accent) 9%, var(--surface)); }
.lm-avatar { position: relative; flex: none; }
.lm-dot { position: absolute; bottom: -1px; inset-inline-end: -1px; width: 10px; height: 10px; border-radius: 50%; border: 2px solid var(--panel-solid); background: var(--gray); }
.lm-dot.live { background: var(--green); }
.lm-dot.recent { background: var(--amber); }
.lm-item-main { display: flex; flex-direction: column; min-width: 0; flex: 1; }
.lm-item-main b { font-size: 13.5px; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.lm-item-main small { font-size: 11.5px; color: var(--text-3); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.lm-nums { display: flex; gap: 8px; flex: none; font-family: var(--mono); font-size: 12px; color: var(--text-2); }
.lm-nums span { display: inline-flex; align-items: center; gap: 3px; }
.lm-nums svg { width: 13px; height: 13px; }
.lm-focus { display: flex; flex-direction: column; gap: 12px; padding: 14px; border-radius: var(--r-lg); border: 1px solid var(--border-strong); background: var(--surface); box-shadow: var(--shadow-sm); }
.lm-focus-head { display: flex; align-items: center; gap: 10px; }
.lm-focus-head b { display: block; font-size: 14.5px; }
.lm-focus-head a { font-size: 12px; }
.lm-focus-nums { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 6px; }
.lm-focus-nums div { display: flex; flex-direction: column; align-items: center; gap: 2px; padding: 7px 4px; border-radius: 11px; background: var(--surface-2); text-align: center; }
.lm-focus-nums b { font-size: 14px; font-family: var(--mono); }
.lm-focus-nums span { font-size: 10.5px; color: var(--text-3); }
.lm-stops { display: flex; flex-direction: column; gap: 5px; }
.lm-stops h4 { font-size: 12px; font-weight: 600; color: var(--text-2); text-transform: uppercase; letter-spacing: .06em; margin-bottom: 2px; }
:root[lang="ar"] .lm-stops h4 { letter-spacing: 0; }
.lm-stop { display: flex; align-items: center; gap: 9px; width: 100%; padding: 7px 8px; border-radius: 10px; text-align: start; color: var(--text); }
.lm-stop:hover { background: var(--surface-2); }
.lm-stop .grow { display: flex; flex-direction: column; min-width: 0; }
.lm-stop b { font-size: 13px; font-weight: 600; }
.lm-stop small { font-size: 11.5px; color: var(--text-3); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.lm-stop-n { width: 22px; height: 22px; flex: none; display: grid; place-items: center; border-radius: 50%; background: var(--grad); color: var(--on-accent, #fff); font-size: 11px; font-weight: 700; font-family: var(--mono); }
.lm-trail-note { font-size: 11.5px; }

@media (max-width: 900px) {
  .lm-layout { grid-template-columns: minmax(0, 1fr); }
  .lm-map { height: 56vh; height: 56dvh; min-height: 300px; }
  .lm-side { max-height: none; overflow: visible; }
  .lm-focus-nums { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}

/* ---------- 4. arrival estimate (tracking page) ---------- */

.eta-card { gap: 12px; }
.eta-body { display: flex; align-items: center; gap: 12px; }
.eta-icon { width: 44px; height: 44px; flex: none; display: grid; place-items: center; border-radius: 14px; background: color-mix(in srgb, var(--accent) 14%, transparent); color: var(--accent); }
.eta-icon svg { width: 22px; height: 22px; }
.eta-icon.is-next { background: color-mix(in srgb, var(--green) 16%, transparent); color: var(--green); animation: dotPulse 1.8s ease-in-out infinite; }
.eta-text { display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.eta-text b { font-size: 15.5px; font-weight: 700; }
.eta-text span { font-size: 14px; color: var(--text); font-variant-numeric: tabular-nums; }
.eta-text small { font-size: 11.5px; color: var(--text-3); }
.eta-map-host:empty { display: none; }
.eta-map { height: 210px; min-height: 0; }

/* ---------- 5. ratings ---------- */

.stars { display: inline-flex; align-items: center; gap: 1px; color: var(--amber); flex: none; }
.stars svg { width: 17px; height: 17px; }
.stars svg.on { fill: currentColor; }
.stars svg.half { fill: currentColor; opacity: .55; }
.stars svg.off { color: var(--text-3); opacity: .55; }
.stars.sm svg { width: 13px; height: 13px; }
.rt-comment { margin: 0; padding: 8px 12px; border-inline-start: 3px solid var(--amber); border-radius: 8px; background: var(--surface-2); font-size: 13.5px; color: var(--text); white-space: pre-wrap; }
.rt-meta { font-size: 12px; }
.rt-drivers { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 10px; }
.rt-drivers[hidden] { display: none; }
.rt-driver { align-items: stretch; gap: 7px; padding: 14px; text-align: start; color: var(--text); cursor: pointer; }
.rt-driver.is-active { border-color: var(--accent); box-shadow: 0 0 0 1px var(--accent) inset; }
.rt-driver-head { display: flex; align-items: center; gap: 8px; }
.rt-driver-head b { font-size: 13.5px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.rt-avg { font-size: 18px; font-weight: 700; font-family: var(--mono); }
.rt-dist { display: flex; flex-direction: column; gap: 3px; }
.rt-dist-row { display: grid; grid-template-columns: 26px 1fr 30px; align-items: center; gap: 6px; font-size: 11px; color: var(--text-3); font-family: var(--mono); }
.rt-dist-row small { text-align: end; }
.rt-dist-track { display: block; height: 6px; border-radius: 99px; background: var(--surface-3); overflow: hidden; }
.rt-dist-track b { display: block; height: 100%; border-radius: inherit; background: var(--amber); }
.rt-dist-track b.s5, .rt-dist-track b.s4 { background: var(--green); }
.rt-dist-track b.s2, .rt-dist-track b.s1 { background: var(--rose); }
.rt-said { display: flex; flex-direction: column; gap: 5px; max-width: 460px; }
.rt-comment-cell { font-size: 13px; color: var(--text); white-space: normal; }
.rt-tag svg { color: var(--amber); fill: currentColor; }
.rt-detail-head { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.rt-big { font-size: 28px; font-weight: 700; font-family: var(--mono); line-height: 1; }
.rt-line { display: flex; align-items: center; gap: 10px; width: 100%; padding: 8px 6px; border-radius: 10px; text-align: start; color: var(--text); font-size: 13px; }
.rt-line:hover { background: var(--surface-2); }

/* ---------- 6. driver app: location chip, route order ---------- */

.drv-loc { display: inline-flex; align-items: center; gap: 5px; height: 28px; padding: 0 9px; border-radius: 99px; font-size: 11.5px; font-weight: 600; white-space: nowrap; border: 1px solid var(--border); background: var(--surface); color: var(--text-2); flex: none; }
.drv-loc svg { width: 14px; height: 14px; }
.drv-loc.on { color: var(--green); border-color: color-mix(in srgb, var(--green) 35%, transparent); background: color-mix(in srgb, var(--green) 9%, transparent); }
.drv-loc.on svg { animation: dotPulse 1.8s ease-in-out infinite; }
.drv-loc.off { color: var(--amber); border-color: color-mix(in srgb, var(--amber) 35%, transparent); background: color-mix(in srgb, var(--amber) 9%, transparent); }
@media (max-width: 400px) {
  .drv-loc span { display: none; }
  .drv-loc { width: 28px; padding: 0; justify-content: center; }
}
.drv-route { display: flex; align-items: center; gap: 9px; padding: 9px 12px; border-radius: 14px; border: 1px dashed var(--border-strong); background: var(--surface); font-size: 13px; color: var(--text-2); }
.drv-route > svg { width: 17px; height: 17px; color: var(--accent); flex: none; }
.drv-route.is-editing { border-style: solid; border-color: color-mix(in srgb, var(--accent) 45%, transparent); background: color-mix(in srgb, var(--accent) 7%, var(--surface)); color: var(--text); }
.drv-reorder { display: flex; flex-direction: column; gap: 10px; }
.drv-route-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 6px; }
.drv-route-item { display: flex; align-items: center; gap: 10px; padding: 10px; border-radius: 14px; border: 1px solid var(--border); background: var(--surface); }
.drv-route-n { width: 28px; height: 28px; flex: none; display: grid; place-items: center; border-radius: 50%; background: var(--grad); color: var(--on-accent, #fff); font-size: 12.5px; font-weight: 700; font-family: var(--mono); }
.drv-route-main { display: flex; flex-direction: column; min-width: 0; flex: 1; }
.drv-route-main b { font-size: 14px; }
.drv-route-main small { font-size: 12px; color: var(--text-3); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.drv-route-pin { display: inline-flex; align-items: center; gap: 3px; color: var(--green) !important; }
.drv-route-pin svg { width: 12px; height: 12px; }
.drv-move { width: 40px; height: 40px; flex: none; display: grid; place-items: center; border-radius: 12px; border: 1px solid var(--border); background: var(--surface-2); color: var(--text); }
.drv-move:disabled { opacity: .35; }
.drv-move:not(:disabled):active { transform: scale(.92); }
.drv-move svg { width: 18px; height: 18px; }
.drv-reorder-foot { position: sticky; bottom: calc(76px + env(safe-area-inset-bottom)); display: flex; gap: 8px; justify-content: flex-end; padding: 10px; border-radius: 16px; background: var(--panel-solid); border: 1px solid var(--border); box-shadow: var(--shadow); }
.drv-reorder-foot .btn-primary { flex: 1; justify-content: center; }
