/* ============================================================
   RiderTrack — responsive app styles (mobile-first)
   ============================================================ */
:root {
  --navy: #1f2a44;
  --navy-2: #2a3859;
  --blue: #4f8cff;
  --blue-dark: #2f6fe4;
  --green: #22b07d;
  --amber: #f5a524;
  --red: #e85454;
  --bg: #f4f6fb;
  --card: #ffffff;
  --ink: #1b2436;
  --ink-2: #5b6779;
  --line: #e5eaf2;
  --shadow: 0 6px 24px rgba(31, 42, 68, .08);
  --radius: 16px;
  --safe-b: env(safe-area-inset-bottom, 0px);
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
[hidden] { display: none !important; }
html, body { margin: 0; padding: 0; height: 100%; }
body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  color: var(--ink);
  background: var(--bg);
  font-size: 15px;
  line-height: 1.45;
}
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
h1, h2, h3, h4, p { margin: 0; }
.muted { color: var(--ink-2); }
.hidden { display: none !important; }

/* ---------- Buttons ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  border: 1px solid transparent; border-radius: 10px; padding: 11px 16px;
  font-weight: 600; background: #eef1f7; color: var(--ink);
  transition: transform .08s ease, opacity .15s ease, background .15s ease;
}
.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn-primary { background: var(--blue); color: #fff; }
.btn-primary:hover:not(:disabled) { background: var(--blue-dark); }
.btn-green { background: var(--green); color: #fff; }
.btn-amber { background: var(--amber); color: #3a2a00; }
.btn-danger { background: #fdecec; color: var(--red); border-color: #f8cfcf; }
.btn-ghost { background: transparent; border-color: var(--line); }
.btn-sm { padding: 7px 11px; font-size: 13px; border-radius: 8px; }
.btn-block { width: 100%; }
.icon-btn {
  border: none; background: transparent; font-size: 20px; line-height: 1;
  padding: 8px; border-radius: 8px; color: var(--ink-2);
}
.icon-btn:hover { background: #eef1f7; }

/* ---------- Login ---------- */
.login-screen {
  min-height: 100%; display: flex; align-items: center; justify-content: center;
  padding: 24px; background: radial-gradient(1200px 600px at 80% -10%, #dce8ff 0%, transparent 55%),
                              radial-gradient(900px 500px at 0% 100%, #dff5ec 0%, transparent 50%), var(--bg);
}
.login-card {
  width: 100%; max-width: 420px; background: var(--card); border-radius: 22px;
  padding: 32px 28px; box-shadow: var(--shadow); border: 1px solid var(--line);
}
.brand { display: flex; align-items: center; gap: 14px; margin-bottom: 26px; }
.brand-mark {
  width: 54px; height: 54px; border-radius: 14px; background: var(--navy);
  color: #7fb0ff; display: grid; place-items: center; flex: 0 0 auto;
}
.brand-mark svg { width: 34px; height: 34px; }
.brand-mark.small { width: 34px; height: 34px; border-radius: 9px; }
.brand-mark.small svg { width: 22px; height: 22px; }
.brand h1 { font-size: 22px; letter-spacing: -.4px; }
.brand p { color: var(--ink-2); font-size: 13px; }
.demo-banner {
  background: #fff8e8; border: 1px solid #f6dfae; color: #8a6100;
  border-radius: 10px; padding: 10px 12px; font-size: 13px; margin-bottom: 18px;
}
.login-form label { display: block; font-weight: 600; font-size: 13px; margin-bottom: 14px; }
.login-form input, .field input, .field select, .field textarea {
  width: 100%; margin-top: 6px; padding: 12px 13px; border: 1px solid var(--line);
  border-radius: 10px; background: #fbfcfe; outline: none;
}
.login-form input:focus, .field input:focus, .field select:focus, .field textarea:focus {
  border-color: var(--blue); background: #fff; box-shadow: 0 0 0 3px rgba(79,140,255,.15);
}
.form-error { color: var(--red); font-size: 13px; margin: -4px 0 12px; }
.login-help { margin-top: 18px; font-size: 13px; color: var(--ink-2); }
.login-help summary { cursor: pointer; font-weight: 600; }
.login-help p { margin-top: 6px; }
code { background: #eef1f7; padding: 1px 5px; border-radius: 5px; }

/* ---------- App shell ---------- */
.app-shell { display: flex; min-height: 100%; }
.sidebar {
  width: 232px; background: var(--navy); color: #c8d2e6; display: flex;
  flex-direction: column; position: fixed; inset: 0 auto 0 0; z-index: 30;
}
.sidebar-brand {
  display: flex; align-items: center; gap: 10px; padding: 20px 18px;
  color: #fff; font-weight: 700; font-size: 17px; border-bottom: 1px solid rgba(255,255,255,.08);
}
.side-nav { padding: 14px 10px; display: flex; flex-direction: column; gap: 4px; flex: 1; overflow-y: auto; }
.side-link, .nav-item {
  display: flex; align-items: center; gap: 11px; width: 100%; text-align: left;
  padding: 11px 12px; border-radius: 10px; border: none; background: transparent;
  color: #c8d2e6; font-weight: 600; font-size: 14px;
}
.nav-item:hover, .side-link:hover { background: rgba(255,255,255,.07); color: #fff; }
.nav-item.active { background: var(--blue); color: #fff; }
.nav-item .ico { width: 20px; text-align: center; opacity: .95; }
.sidebar-foot { padding: 12px 10px calc(16px + var(--safe-b)); border-top: 1px solid rgba(255,255,255,.08); }
.sidebar-foot .side-link { font-size: 13px; font-weight: 500; }

.app-main { flex: 1; margin-left: 232px; min-width: 0; display: flex; flex-direction: column; }
.topbar {
  height: 68px; background: var(--card); border-bottom: 1px solid var(--line);
  display: flex; align-items: center; justify-content: space-between; padding: 0 24px;
  position: sticky; top: 0; z-index: 20;
}
.topbar-left { display: flex; align-items: center; gap: 12px; }
.topbar h2 { font-size: 18px; letter-spacing: -.2px; }
.topbar p { font-size: 12px; }
.topbar-right { display: flex; align-items: center; gap: 14px; }
.menu-btn { display: none; }
.user-chip { display: flex; align-items: center; gap: 10px; }
.avatar {
  width: 36px; height: 36px; border-radius: 50%; background: var(--navy); color: #fff;
  display: grid; place-items: center; font-weight: 700; font-size: 14px;
}
.user-meta { display: flex; flex-direction: column; line-height: 1.2; }
.user-meta strong { font-size: 13px; }
.user-meta span { font-size: 11px; }
.pill { font-size: 11px; font-weight: 700; padding: 4px 9px; border-radius: 99px; }
.pill-ghost { background: #fff4dd; color: #8a6100; border: 1px solid #f2dca8; }

.content { padding: 22px 24px 40px; flex: 1; }
.bottom-nav { display: none; }

/* ---------- Cards, grids, stats ---------- */
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); }
.card-pad { padding: 18px; }
.card-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 16px 18px; border-bottom: 1px solid var(--line); }
.card-head h3 { font-size: 15px; }
.card-body { padding: 18px; }
.grid { display: grid; gap: 16px; }
.grid-4 { grid-template-columns: repeat(4, 1fr); }
.grid-3 { grid-template-columns: repeat(3, 1fr); }
.grid-2 { grid-template-columns: repeat(2, 1fr); }
.stack { display: flex; flex-direction: column; gap: 16px; }
.row { display: flex; gap: 12px; align-items: center; flex-wrap: wrap; }
.spread { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.section-title { font-size: 14px; font-weight: 700; color: var(--ink-2); text-transform: uppercase; letter-spacing: .5px; margin: 4px 0 12px; }

.stat {
  background: var(--card); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 16px 18px; box-shadow: var(--shadow); position: relative; overflow: hidden;
}
.stat .label { font-size: 12px; color: var(--ink-2); font-weight: 600; }
.stat .value { font-size: 26px; font-weight: 800; margin-top: 6px; letter-spacing: -.6px; }
.stat .sub { font-size: 12px; color: var(--ink-2); margin-top: 4px; }
.stat .accent { position: absolute; left: 0; top: 0; bottom: 0; width: 4px; background: var(--blue); }
.stat.g .accent { background: var(--green); }
.stat.a .accent { background: var(--amber); }
.stat.r .accent { background: var(--red); }

/* ---------- Tables ---------- */
.table-wrap { overflow-x: auto; }
table.tbl { width: 100%; border-collapse: collapse; font-size: 13px; min-width: 620px; }
.tbl th { text-align: left; font-size: 11px; text-transform: uppercase; letter-spacing: .4px; color: var(--ink-2); padding: 11px 14px; border-bottom: 1px solid var(--line); white-space: nowrap; }
.tbl td { padding: 12px 14px; border-bottom: 1px solid var(--line); vertical-align: middle; }
.tbl tr:last-child td { border-bottom: none; }
.tbl tbody tr:hover { background: #fafbfe; }
.tbl .num { text-align: right; font-variant-numeric: tabular-nums; }

.badge { display: inline-flex; align-items: center; gap: 6px; font-size: 11px; font-weight: 700; padding: 4px 9px; border-radius: 99px; white-space: nowrap; }
.badge::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: currentColor; }
.badge.assigned { background: #eef1f7; color: #5b6779; }
.badge.in_progress { background: #e7f0ff; color: var(--blue-dark); }
.badge.completed { background: #fff3dc; color: #9a6a00; }
.badge.returned { background: #e4f7ef; color: #128259; }
.badge.admin { background: #ece8ff; color: #6a45d8; }
.badge.rider { background: #e7f0ff; color: var(--blue-dark); }
.badge.inactive { background: #fdecec; color: var(--red); }

.empty { text-align: center; padding: 40px 20px; color: var(--ink-2); }
.empty .big { font-size: 34px; margin-bottom: 8px; }

/* ---------- Forms / filters ---------- */
.filters { display: flex; gap: 10px; flex-wrap: wrap; align-items: flex-end; }
.field { display: flex; flex-direction: column; font-size: 12px; font-weight: 600; color: var(--ink-2); }
.field input, .field select { min-width: 150px; }
.field-row { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }

/* ---------- Task cards (rider) ---------- */
.task-card { padding: 16px; border-radius: 14px; }
.task-card .route { display: flex; flex-direction: column; gap: 7px; margin: 12px 0; }
.route-line { display: flex; gap: 10px; align-items: flex-start; font-size: 14px; }
.dot { width: 10px; height: 10px; border-radius: 50%; margin-top: 5px; flex: 0 0 auto; }
.dot.dropoff { background: var(--green); }
.route .connector { width: 2px; height: 12px; background: var(--line); margin-left: 4px; }

/* ---------- Active tracker ---------- */
.tracker { padding: 18px; }
.tracker h3 { font-size: 17px; }
.tracker .timer { font-size: 40px; font-weight: 800; letter-spacing: -1px; font-variant-numeric: tabular-nums; }
.tracker .dist { font-size: 24px; font-weight: 800; color: var(--blue-dark); font-variant-numeric: tabular-nums; }
.stepper { display: flex; gap: 6px; margin: 18px 0; }
.step { flex: 1; text-align: center; font-size: 10px; font-weight: 700; color: var(--ink-2); }
.step .bar { height: 6px; border-radius: 99px; background: var(--line); margin-bottom: 6px; }
.step.done .bar { background: var(--green); }
.step.current .bar { background: var(--blue); }
.map-box { height: 190px; background: #eef2f8; border-radius: 12px; overflow: hidden; border: 1px solid var(--line); }
.map-box svg { width: 100%; height: 100%; display: block; }
.gps-note { font-size: 12px; color: var(--ink-2); margin-top: 10px; }
.gps-note.warn { color: #9a6a00; }
.timeline { list-style: none; padding: 0; margin: 0; }
.timeline li { position: relative; padding: 0 0 16px 22px; font-size: 13px; }
.timeline li::before { content: ""; position: absolute; left: 4px; top: 5px; width: 9px; height: 9px; border-radius: 50%; background: var(--blue); }
.timeline li::after { content: ""; position: absolute; left: 8px; top: 16px; bottom: 0; width: 2px; background: var(--line); }
.timeline li:last-child::after { display: none; }
.timeline time { color: var(--ink-2); font-size: 12px; }

/* ---------- Modal ---------- */
.modal-backdrop {
  position: fixed; inset: 0; background: rgba(18, 26, 43, .5); z-index: 60;
  display: flex; align-items: center; justify-content: center; padding: 18px;
}
.modal { width: 100%; max-width: 520px; background: #fff; border-radius: 18px; box-shadow: 0 20px 60px rgba(0,0,0,.25); max-height: 90vh; display: flex; flex-direction: column; }
.modal-head { display: flex; align-items: center; justify-content: space-between; padding: 18px 20px; border-bottom: 1px solid var(--line); }
.modal-head h3 { font-size: 17px; }
.modal-body { padding: 20px; overflow-y: auto; }
.modal-foot { padding: 14px 20px calc(18px + var(--safe-b)); border-top: 1px solid var(--line); display: flex; justify-content: flex-end; gap: 10px; }
.modal-body .field { margin-bottom: 14px; }

/* ---------- Toasts ---------- */
.toast-wrap { position: fixed; right: 18px; bottom: calc(18px + var(--safe-b)); z-index: 80; display: flex; flex-direction: column; gap: 10px; }
.toast { background: var(--navy); color: #fff; padding: 12px 16px; border-radius: 10px; box-shadow: var(--shadow); font-size: 13px; max-width: 320px; animation: slidein .2s ease; }
.toast.err { background: var(--red); }
.toast.ok { background: var(--green); }
@keyframes slidein { from { transform: translateY(8px); opacity: 0; } }

/* ---------- Responsive ---------- */
@media (max-width: 900px) {
  .grid-4 { grid-template-columns: repeat(2, 1fr); }
  .grid-3 { grid-template-columns: 1fr; }
}
@media (max-width: 720px) {
  body { font-size: 14px; }
  .sidebar { transform: translateX(-100%); transition: transform .2s ease; width: 250px; }
  .sidebar.open { transform: translateX(0); }
  .app-main { margin-left: 0; }
  .menu-btn { display: inline-grid; }
  .topbar { padding: 0 14px; height: 60px; }
  .topbar h2 { font-size: 16px; }
  .user-meta { display: none; }
  .content { padding: 14px 14px 90px; }
  .grid-2, .grid-4 { grid-template-columns: 1fr 1fr; }
  .grid-4 { gap: 10px; }
  .stat { padding: 13px; }
  .stat .value { font-size: 21px; }
  .bottom-nav {
    display: flex; position: fixed; left: 0; right: 0; bottom: 0; z-index: 25;
    background: #fff; border-top: 1px solid var(--line); padding-bottom: var(--safe-b);
  }
  .bottom-nav button {
    flex: 1; border: none; background: transparent; padding: 9px 4px 8px;
    display: flex; flex-direction: column; align-items: center; gap: 3px;
    font-size: 10px; font-weight: 700; color: var(--ink-2);
  }
  .bottom-nav button .ico { font-size: 19px; }
  .bottom-nav button.active { color: var(--blue); }
  .field-row { grid-template-columns: 1fr; }
  .filters .field, .filters input, .filters select { flex: 1; min-width: 120px; }
  .tracker .timer { font-size: 34px; }
}
@media (max-width: 420px) {
  .grid-2, .grid-4 { grid-template-columns: 1fr; }
}

/* ---------- v2: routes, maps, progress ---------- */
.map-box, .mini-map { position: relative; z-index: 1; isolation: isolate; }
.map-box { height: 260px; }
.mini-map { height: 150px; border-radius: 12px; overflow: hidden; margin-top: 12px; border: 1px solid var(--line); background: #e9eef5; }
.big-map { height: 300px; margin-top: 14px; }
.leaflet-container { background: #e9eef5; font-family: inherit; }
.map-fallback { height: 100%; display: grid; place-items: center; color: var(--ink-2); font-size: 13px; background: #e9eef5; }
.mini-map .map-fallback, .map-box .map-fallback { min-height: 100%; }
.leaflet-control-attribution { font-size: 9px !important; }

/* custom pins (no external marker images) */
.pin-wrap { background: transparent; border: none; }
.map-pin { width: 26px; height: 26px; border-radius: 50% 50% 50% 4px; transform: rotate(-45deg);
  box-shadow: 0 2px 6px rgba(0,0,0,.3); border: 2px solid #fff; display: grid; place-items: center; }
.map-pin.pin-origin { background: var(--navy); }
.map-pin.pin-stop { background: var(--amber); }
.map-pin.pin-done { background: var(--green); }
.map-pin.pin-rider { background: var(--blue); width: 22px; height: 22px; }
.map-pin.pin-stop span { width: 7px; height: 7px; background: #fff; border-radius: 50%; }
.map-label { position: absolute; left: 30px; top: -3px; white-space: nowrap; background: #fff; color: var(--ink);
  font-size: 10px; font-weight: 700; padding: 3px 7px; border-radius: 6px; box-shadow: 0 1px 5px rgba(0,0,0,.18); }
.map-label-rider { color: var(--blue-dark); }

.progress { height: 8px; background: var(--line); border-radius: 99px; overflow: hidden; margin-top: 14px; }
.progress-bar { height: 100%; background: linear-gradient(90deg, var(--blue), var(--green)); border-radius: 99px; transition: width .3s ease; }
.next-stop { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-top: 16px;
  padding: 13px 15px; border-radius: 12px; background: #eef4ff; border: 1px solid #d4e3ff; }
.next-stop.done-stop { background: #eaf8f2; border-color: #c8ecdb; }
.leg-list { margin-top: 14px; }

.route-list { display: flex; flex-direction: column; gap: 8px; }
.route-item { display: flex; align-items: center; gap: 12px; padding: 10px 12px; border: 1px solid var(--line); border-radius: 11px; background: #fbfcfe; }
.route-num { width: 28px; height: 28px; border-radius: 50%; background: var(--navy); color: #fff; display: grid; place-items: center; font-weight: 700; font-size: 12px; flex: 0 0 auto; }
.route-info { flex: 1; min-width: 0; font-size: 13px; }
.route-actions { display: flex; gap: 2px; }
.route-actions .icon-btn { font-size: 17px; padding: 6px; }
.stop-edit { flex-wrap: wrap; }
.km-field { flex: 0 0 auto; }
.km-field label { display: block; font-size: 10px; font-weight: 700; color: var(--ink-2); text-transform: uppercase; letter-spacing: .04em; }
.km-field input { width: 92px; padding: 6px 8px; margin-top: 3px; font-size: 13px; }

@media (max-width: 720px) {
  .map-box { height: 220px; }
  .mini-map { height: 130px; }
  .next-stop { flex-direction: column; align-items: flex-start; }
}
