/* Rider tracking dashboard. RTL, one typeface, status colors carry meaning. */
:root {
  --ink: #1b2433;
  --ink-2: #445066;
  --muted: #6b7686;
  --bg: #eef1f4;
  --surface: #ffffff;
  --sunken: #f5f7f9;
  --rule: #dce1e7;
  --rule-strong: #c4ccd6;
  --nav-text: #c9d1dc;

  --available: #1f9d55;
  --on-order: #2563eb;
  --stale: #d9480f;
  --offline: #7a8494;
  --danger: #c92a2a;

  --radius-s: 6px;
  --radius-m: 10px;
  --shadow: 0 1px 2px rgba(27, 36, 51, 0.08), 0 4px 16px rgba(27, 36, 51, 0.08);

  --fs-xs: 12px;
  --fs-s: 13px;
  --fs-m: 14px;
  --fs-l: 16px;
  --fs-xl: 20px;
  --fs-2xl: 26px;

  --topbar-h: 56px;
  --panel-w: 360px;
  font-family: "IBM Plex Sans Arabic", system-ui, sans-serif;
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body { overflow-x: hidden; }
body {
  background: var(--bg);
  color: var(--ink);
  font-size: var(--fs-m);
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
}
[hidden] { display: none !important; }
button, input, select, textarea { font: inherit; color: inherit; }
a { color: var(--on-order); }
h1, h2, h3 { line-height: 1.3; margin: 0; }
.num { font-variant-numeric: tabular-nums; }

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

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

/* ---------- buttons & fields ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  min-height: 36px; padding: 0 14px;
  border: 1px solid var(--rule-strong); border-radius: var(--radius-s);
  background: var(--surface); color: var(--ink);
  font-weight: 500; cursor: pointer; text-decoration: none; white-space: nowrap;
}
.btn:hover { background: var(--sunken); }
.btn:disabled { opacity: 0.55; cursor: not-allowed; }
.btn--primary { background: var(--ink); border-color: var(--ink); color: #fff; }
.btn--primary:hover { background: #2a364a; }
.btn--danger { color: var(--danger); border-color: #e7b9b9; }
.btn--danger:hover { background: #fdf2f2; }
.btn--ghost { border-color: transparent; background: transparent; }
.btn--small { min-height: 30px; padding: 0 10px; font-size: var(--fs-s); }
.btn--block { width: 100%; }

.field { display: grid; gap: 5px; font-size: var(--fs-s); color: var(--ink-2); }
.field input, .field select, .field textarea, .input {
  width: 100%; min-width: 0;
  min-height: 38px; padding: 6px 10px;
  border: 1px solid var(--rule-strong); border-radius: var(--radius-s);
  background: var(--surface); color: var(--ink); font-size: var(--fs-m);
}
.field input:focus, .field select:focus, .input:focus { outline: 2px solid var(--on-order); outline-offset: -1px; border-color: transparent; }
.field__hint { color: var(--muted); font-size: var(--fs-xs); }
.form-error { margin: 0; color: var(--danger); font-size: var(--fs-s); }

/* ---------- sign-in ---------- */
.login { min-height: 100%; display: grid; grid-template-columns: 1fr minmax(320px, 440px); }
.login__brand {
  background: var(--ink); color: #fff;
  display: flex; flex-direction: column; justify-content: center; gap: 14px;
  padding: 48px 8vw;
  background-image: radial-gradient(circle at 1px 1px, rgba(255,255,255,0.08) 1px, transparent 0);
  background-size: 22px 22px;
}
.login__mark { width: 64px; height: 64px; color: #e6eaf0; }
.login__title { font-size: 40px; font-weight: 700; }
.login__lead { margin: 0; max-width: 34ch; color: var(--nav-text); font-size: var(--fs-l); }
.login__form { background: var(--surface); padding: 48px 40px; display: flex; flex-direction: column; justify-content: center; gap: 16px; }
.login__form h2 { font-size: var(--fs-xl); margin-bottom: 4px; }
@media (max-width: 760px) {
  .login { grid-template-columns: 1fr; }
  .login__brand { padding: 40px 24px; }
  .login__title { font-size: 30px; }
  .login__form { padding: 32px 24px; }
}

/* ---------- shell ---------- */
.app { height: 100%; display: grid; grid-template-rows: var(--topbar-h) 1fr; }
.topbar {
  display: flex; align-items: center; gap: 24px; min-width: 0;
  padding: 0 16px; background: var(--ink); color: #fff;
}
.brand { display: flex; align-items: center; gap: 10px; color: #fff; text-decoration: none; font-weight: 700; font-size: var(--fs-l); white-space: nowrap; }
.brand__mark { width: 30px; height: 30px; color: #e6eaf0; }
.nav { display: flex; gap: 2px; height: 100%; min-width: 0; flex: 0 1 auto; overflow-x: auto; scrollbar-width: none; }
.nav a {
  display: flex; align-items: center; gap: 6px; padding: 0 14px;
  color: var(--nav-text); text-decoration: none; white-space: nowrap;
  border-bottom: 3px solid transparent; border-top: 3px solid transparent;
}
.nav a:hover { color: #fff; }
.nav a[aria-current="page"] { color: #fff; border-bottom-color: #fff; font-weight: 600; }
.nav__badge {
  min-width: 20px; height: 20px; padding: 0 6px; border-radius: 10px;
  background: var(--stale); color: #fff; font-size: var(--fs-xs); font-weight: 700;
  display: inline-flex; align-items: center; justify-content: center;
}
.topbar__end { margin-inline-start: auto; display: flex; align-items: center; gap: 16px; flex: none; }
.conn { display: inline-flex; align-items: center; gap: 6px; font-size: var(--fs-xs); color: var(--nav-text); white-space: nowrap; }
.conn__dot { width: 8px; height: 8px; border-radius: 50%; background: var(--offline); }
.conn[data-state="on"] .conn__dot { background: #3ddc84; box-shadow: 0 0 0 3px rgba(61, 220, 132, 0.2); }
.usermenu { position: relative; }
.usermenu__btn {
  background: rgba(255,255,255,0.08); border: 1px solid rgba(255,255,255,0.14); color: #fff;
  border-radius: var(--radius-s); padding: 5px 12px; cursor: pointer; white-space: nowrap;
}
.usermenu__list {
  position: absolute; inset-inline-end: 0; top: calc(100% + 6px); z-index: 2000;
  min-width: 190px; background: var(--surface); color: var(--ink);
  border: 1px solid var(--rule); border-radius: var(--radius-m); box-shadow: var(--shadow); padding: 6px;
}
.usermenu__list button {
  display: block; width: 100%; text-align: start; padding: 8px 10px;
  background: none; border: 0; border-radius: var(--radius-s); cursor: pointer;
}
.usermenu__list button:hover { background: var(--sunken); }
.view { min-height: 0; overflow: auto; }

@media (max-width: 900px) {
  .topbar { gap: 10px; padding: 0 10px; }
  .brand__name, .conn__text { display: none; }
  .nav a { padding: 0 9px; font-size: var(--fs-s); }
  .usermenu__btn { max-width: 96px; overflow: hidden; text-overflow: ellipsis; }
  .page { padding: 16px 12px 40px; }
}
@media (max-width: 480px) {
  .conn { display: none; }
  .figures { grid-template-columns: repeat(2, 1fr); }
}

/* ---------- map layouts ---------- */
.mapview { height: 100%; display: grid; grid-template-columns: var(--panel-w) 1fr; min-height: 0; }
.panel { background: var(--surface); border-inline-end: 1px solid var(--rule); display: flex; flex-direction: column; min-height: 0; }
.panel__section { padding: 14px 16px; border-bottom: 1px solid var(--rule); }
.panel__scroll { flex: 1; overflow-y: auto; min-height: 0; }
.panel h2 { font-size: var(--fs-l); }
.map { position: relative; min-height: 0; background: #dfe5ea; }
.map .leaflet-container { height: 100%; width: 100%; direction: ltr; font: inherit; background: #e6ebef; }
.leaflet-popup-content { direction: rtl; text-align: right; font-family: "IBM Plex Sans Arabic", sans-serif; font-size: var(--fs-s); margin: 10px 14px; }
@media (max-width: 900px) {
  .mapview { grid-template-columns: 1fr; grid-template-rows: 55vh auto; }
  .mapview > .map { order: -1; }
  .panel { border-inline-end: 0; border-top: 1px solid var(--rule); }
  .panel__scroll { overflow: visible; }
}

/* ---------- status composition bar ---------- */
.composition { display: grid; gap: 10px; }
.composition__head { display: flex; align-items: baseline; justify-content: space-between; gap: 8px; }
.composition__total { font-size: var(--fs-2xl); font-weight: 700; line-height: 1; }
.composition__caption { color: var(--muted); font-size: var(--fs-s); }
.composition__bar { display: flex; height: 10px; gap: 2px; border-radius: 5px; overflow: hidden; background: var(--sunken); }
.composition__bar span { display: block; height: 100%; min-width: 4px; }
.legend { display: flex; flex-wrap: wrap; gap: 6px; }
.chip {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 3px 10px; border: 1px solid var(--rule); border-radius: 999px;
  background: var(--surface); cursor: pointer; font-size: var(--fs-s); color: var(--ink-2);
}
.chip:hover { border-color: var(--rule-strong); }
.chip[aria-pressed="true"] { background: var(--ink); color: #fff; border-color: var(--ink); }
.chip b { font-weight: 600; color: inherit; }

.dot { width: 9px; height: 9px; border-radius: 50%; flex: none; display: inline-block; }
.dot--available { background: var(--available); }
.dot--on_order { background: var(--on-order); }
.dot--stale { background: var(--stale); }
.dot--offline { background: transparent; border: 2px solid var(--offline); }

.search { width: 100%; }

/* ---------- rider list ---------- */
.riders { list-style: none; margin: 0; padding: 0; }
.rider {
  display: grid; grid-template-columns: 36px 1fr auto; gap: 10px; align-items: center;
  padding: 10px 16px; border-bottom: 1px solid var(--sunken); cursor: pointer;
}
.rider:hover { background: var(--sunken); }
.rider[aria-selected="true"] { background: #e8eefc; box-shadow: inset -3px 0 0 var(--on-order); }
.rider__avatar {
  width: 36px; height: 36px; border-radius: 50%;
  display: grid; place-items: center; font-weight: 700; font-size: var(--fs-s);
  background: var(--sunken); border: 2px solid var(--offline); color: var(--ink);
}
.rider__avatar--available { border-color: var(--available); }
.rider__avatar--on_order { border-color: var(--on-order); }
.rider__avatar--stale { border-color: var(--stale); }
.rider__name { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.rider__meta { color: var(--muted); font-size: var(--fs-xs); display: flex; gap: 8px; flex-wrap: wrap; }
.rider__side { text-align: end; font-size: var(--fs-xs); color: var(--muted); white-space: nowrap; }
.rider__side .status { font-size: var(--fs-xs); }
.group-title { padding: 10px 16px 6px; font-size: var(--fs-xs); color: var(--muted); background: var(--sunken); border-bottom: 1px solid var(--rule); }

.status { display: inline-flex; align-items: center; gap: 5px; font-weight: 600; font-size: var(--fs-s); }
.status--available { color: #157a41; }
.status--on_order { color: var(--on-order); }
.status--stale { color: var(--stale); }
.status--offline { color: var(--offline); }

.empty { padding: 28px 18px; text-align: center; color: var(--muted); }
.empty strong { display: block; color: var(--ink); margin-bottom: 4px; }

/* ---------- map markers ---------- */
.rm {
  position: relative; width: 34px; height: 34px; border-radius: 50%;
  background: #fff; border: 3px solid var(--offline);
  display: grid; place-items: center;
  font-family: "IBM Plex Sans Arabic", sans-serif; font-weight: 700; font-size: 13px; color: var(--ink);
  box-shadow: 0 1px 3px rgba(0,0,0,0.3);
}
.rm--available { border-color: var(--available); }
.rm--on_order { border-color: var(--on-order); background: #eef3fe; }
.rm--stale { border-color: var(--stale); border-style: dashed; }
.rm--selected { transform: scale(1.18); box-shadow: 0 0 0 4px rgba(37, 99, 235, 0.25), 0 1px 3px rgba(0,0,0,0.3); }
.rm__heading {
  position: absolute; top: 50%; left: 50%; width: 0; height: 0;
  transform: rotate(var(--h, 0deg)) translateY(-27px);
}
.rm__heading::before {
  content: ""; position: absolute; left: -5px; top: -4px;
  border-left: 5px solid transparent; border-right: 5px solid transparent; border-bottom: 8px solid var(--ink);
}
.rm__badge {
  position: absolute; top: -6px; right: -6px; width: 16px; height: 16px; border-radius: 50%;
  background: var(--stale); color: #fff; font-size: 11px; line-height: 16px; text-align: center;
}
.rm__badge--order { background: var(--on-order); }
.leaflet-marker-icon.rm-wrap { background: none; border: 0; }

/* ---------- floating detail card ---------- */
.detail {
  position: absolute; z-index: 1000; inset-inline-start: 14px; bottom: 14px;
  width: min(340px, calc(100% - 28px));
  background: var(--surface); border-radius: var(--radius-m); box-shadow: var(--shadow);
  border: 1px solid var(--rule);
}
.detail__head { display: flex; align-items: flex-start; gap: 10px; padding: 14px 16px 10px; }
.detail__name { font-size: var(--fs-l); font-weight: 700; }
.detail__close { margin-inline-start: auto; background: none; border: 0; cursor: pointer; font-size: 20px; line-height: 1; color: var(--muted); padding: 2px 6px; }
.facts { display: grid; grid-template-columns: 1fr 1fr; gap: 1px; background: var(--rule); border-top: 1px solid var(--rule); border-bottom: 1px solid var(--rule); }
.fact { background: var(--surface); padding: 8px 16px; }
.fact__label { font-size: var(--fs-xs); color: var(--muted); }
.fact__value { font-weight: 600; font-variant-numeric: tabular-nums; }
.detail__actions { display: flex; gap: 8px; padding: 12px 16px; flex-wrap: wrap; }

.map-tools { position: absolute; z-index: 900; top: 12px; inset-inline-start: 12px; display: flex; gap: 6px; }
.map-tools .btn { box-shadow: var(--shadow); }

/* ---------- routes view ---------- */
.stack { display: grid; gap: 12px; }
.row { display: flex; gap: 10px; align-items: end; flex-wrap: wrap; }
.row > .field { flex: 1 1 120px; min-width: 0; }
.figures { display: grid; grid-template-columns: repeat(3, 1fr); gap: 1px; background: var(--rule); border: 1px solid var(--rule); border-radius: var(--radius-m); overflow: hidden; }
.figure { background: var(--surface); padding: 10px 12px; }
.figure__value { font-size: var(--fs-xl); font-weight: 700; font-variant-numeric: tabular-nums; line-height: 1.2; }
.figure__unit { font-size: var(--fs-s); font-weight: 500; color: var(--ink-2); margin-inline-start: 2px; }
.figure__label { font-size: var(--fs-xs); color: var(--muted); }

.timeline { list-style: none; margin: 0; padding: 0 16px 16px; }
.timeline li { position: relative; padding: 8px 0 8px 0; padding-inline-start: 26px; cursor: pointer; border-radius: var(--radius-s); }
.timeline li:hover { background: var(--sunken); }
.timeline li::before { content: ""; position: absolute; inset-inline-start: 8px; top: 0; bottom: 0; width: 2px; background: var(--rule); }
.timeline li:first-child::before { top: 18px; }
.timeline li:last-child::before { bottom: calc(100% - 18px); }
.tl__mark { position: absolute; inset-inline-start: 3px; top: 13px; width: 12px; height: 12px; border-radius: 50%; border: 2px solid var(--surface); background: var(--ink-2); box-shadow: 0 0 0 1px var(--rule-strong); }
.tl__mark--stop { background: #b7791f; border-radius: 3px; }
.tl__mark--delivered { background: var(--available); }
.tl__mark--picked { background: var(--on-order); }
.tl__mark--alert { background: var(--stale); }
.tl__time { font-size: var(--fs-xs); color: var(--muted); font-variant-numeric: tabular-nums; }
.tl__text { font-size: var(--fs-s); }

.player {
  position: absolute; z-index: 900; bottom: 14px; left: 50%; transform: translateX(-50%);
  width: min(620px, calc(100% - 28px));
  display: flex; align-items: center; gap: 10px;
  background: var(--surface); border: 1px solid var(--rule); border-radius: var(--radius-m); box-shadow: var(--shadow);
  padding: 8px 12px;
}
.player input[type="range"] { flex: 1; accent-color: var(--ink); direction: ltr; }
.player__time { font-variant-numeric: tabular-nums; font-weight: 600; min-width: 66px; text-align: center; }
.player select { min-height: 30px; border: 1px solid var(--rule-strong); border-radius: var(--radius-s); background: var(--surface); padding: 0 6px; }

.stop-icon {
  display: grid; place-items: center; width: 26px; height: 26px; border-radius: 6px;
  background: #b7791f; color: #fff; font-size: 11px; font-weight: 700; border: 2px solid #fff; box-shadow: 0 1px 3px rgba(0,0,0,0.3);
}
.pin-icon {
  display: grid; place-items: center; width: 24px; height: 24px; border-radius: 50%;
  color: #fff; font-size: 11px; font-weight: 700; border: 2px solid #fff; box-shadow: 0 1px 3px rgba(0,0,0,0.35);
}
.pin-icon--start { background: var(--available); }
.pin-icon--end { background: var(--ink); }
.pin-icon--picked { background: var(--on-order); border-radius: 5px; }
.pin-icon--delivered { background: var(--available); border-radius: 5px; }
.pin-icon--alert { background: var(--stale); }
.pin-icon--other { background: var(--offline); }

/* ---------- pages (reports, alerts, settings) ---------- */
.page { max-width: 1180px; margin: 0 auto; padding: 24px 20px 48px; display: grid; gap: 18px; }
.page__head { display: flex; align-items: flex-end; justify-content: space-between; gap: 16px; flex-wrap: wrap; }
.page__title { font-size: var(--fs-xl); font-weight: 700; }
.page__sub { color: var(--muted); margin: 2px 0 0; font-size: var(--fs-s); }
.card { background: var(--surface); border: 1px solid var(--rule); border-radius: var(--radius-m); }
.card__body { padding: 16px; }
.toolbar { display: flex; gap: 8px; align-items: end; flex-wrap: wrap; }
.seg { display: inline-flex; border: 1px solid var(--rule-strong); border-radius: var(--radius-s); overflow: hidden; background: var(--surface); }
.seg button { border: 0; background: none; padding: 7px 12px; cursor: pointer; border-inline-start: 1px solid var(--rule); }
.seg button:first-child { border-inline-start: 0; }
.seg button[aria-pressed="true"] { background: var(--ink); color: #fff; }

.summary { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 1px; background: var(--rule); border: 1px solid var(--rule); border-radius: var(--radius-m); overflow: hidden; }
.summary .figure { padding: 14px 16px; }

.table-wrap { overflow-x: auto; }
table.table { width: 100%; border-collapse: collapse; font-size: var(--fs-m); }
.table th, .table td { padding: 10px 14px; text-align: start; border-bottom: 1px solid var(--rule); white-space: nowrap; }
.table th { font-size: var(--fs-s); color: var(--ink-2); font-weight: 600; background: var(--sunken); position: sticky; top: 0; }
.table th button { all: unset; cursor: pointer; display: inline-flex; gap: 4px; align-items: center; }
.table th button:focus-visible { outline: 2px solid var(--on-order); }
.table td.n, .table th.n { text-align: end; font-variant-numeric: tabular-nums; }
.table tbody tr:hover { background: var(--sunken); }
.table tfoot td { font-weight: 700; background: var(--sunken); border-bottom: 0; }
.table .link { color: var(--ink); font-weight: 600; text-decoration: none; }
.table .link:hover { color: var(--on-order); text-decoration: underline; }

.alerts { list-style: none; margin: 0; padding: 0; }
.alert { display: grid; grid-template-columns: 34px 1fr auto; gap: 12px; align-items: center; padding: 12px 16px; border-bottom: 1px solid var(--rule); }
.alert:last-child { border-bottom: 0; }
.alert__icon { width: 34px; height: 34px; border-radius: 50%; display: grid; place-items: center; font-weight: 700; color: #fff; background: var(--stale); }
.alert__icon--shift_auto_closed { background: var(--offline); }
.alert__icon--mock_location { background: var(--danger); }
.alert__title { font-weight: 600; }
.alert__msg { color: var(--ink-2); font-size: var(--fs-s); }
.alert__time { color: var(--muted); font-size: var(--fs-xs); }
.alert--done { opacity: 0.6; }

.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--rule); }
.tabs button { background: none; border: 0; padding: 10px 14px; cursor: pointer; color: var(--ink-2); border-bottom: 3px solid transparent; margin-bottom: -1px; }
.tabs button[aria-selected="true"] { color: var(--ink); font-weight: 600; border-bottom-color: var(--ink); }

.form-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 16px 20px; }
.form-section { display: grid; gap: 12px; }
.form-section + .form-section { margin-top: 22px; padding-top: 18px; border-top: 1px solid var(--rule); }
.form-section h3 { font-size: var(--fs-l); }
.note { background: var(--sunken); border: 1px solid var(--rule); border-radius: var(--radius-s); padding: 10px 12px; color: var(--ink-2); font-size: var(--fs-s); }

.pill { display: inline-block; padding: 1px 8px; border-radius: 999px; font-size: var(--fs-xs); background: var(--sunken); border: 1px solid var(--rule); color: var(--ink-2); }
.pill--admin { background: #e8eefc; border-color: #c8d6f8; color: #1d4ed8; }
.pill--off { background: #fdf2f2; border-color: #f2caca; color: var(--danger); }

/* ---------- toasts & modal ---------- */
.toasts { position: fixed; z-index: 3000; bottom: 16px; left: 16px; display: grid; gap: 8px; width: min(360px, calc(100% - 32px)); }
.toast {
  background: var(--ink); color: #fff; border-radius: var(--radius-m); padding: 10px 14px; box-shadow: var(--shadow);
  font-size: var(--fs-s); display: flex; gap: 10px; align-items: flex-start;
  animation: toast-in 0.18s ease-out;
}
.toast--alert { background: var(--surface); color: var(--ink); border: 1px solid var(--rule); border-inline-start: 4px solid var(--stale); cursor: pointer; }
.toast--error { background: var(--danger); }
@keyframes toast-in { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }

.modal { border: 0; border-radius: var(--radius-m); padding: 0; width: min(460px, calc(100% - 32px)); box-shadow: var(--shadow); color: var(--ink); }
.modal::backdrop { background: rgba(27, 36, 51, 0.45); }
.modal__body { padding: 20px; display: grid; gap: 14px; }
.modal__title { font-size: var(--fs-l); font-weight: 700; }
.modal__actions { display: flex; gap: 8px; justify-content: flex-end; padding: 12px 20px; background: var(--sunken); border-top: 1px solid var(--rule); }

.spinner { width: 18px; height: 18px; border: 2px solid var(--rule); border-top-color: var(--ink); border-radius: 50%; animation: spin 0.8s linear infinite; display: inline-block; vertical-align: middle; }
@keyframes spin { to { transform: rotate(360deg); } }
