/* Sodiq School bus tracker — brand design system.
   Always light: the brand book is orange / navy / grey, and the map is light, so the page is too. */

@font-face { font-family: "Pragmatica"; src: url("fonts/Pragmatica-Book.woff2") format("woff2"); font-weight: 400; font-display: swap; }
@font-face { font-family: "Pragmatica"; src: url("fonts/Pragmatica-Medium.woff2") format("woff2"); font-weight: 500; font-display: swap; }
@font-face { font-family: "Pragmatica"; src: url("fonts/Pragmatica-Bold.woff2") format("woff2"); font-weight: 700; font-display: swap; }

:root {
  color-scheme: light;
  --orange: #FF8A32;
  --orange-deep: #E07226;
  --orange-soft: #FFE6D3;
  --navy: #06113C;
  --ink: #0B1446;
  --muted: #5B6378;
  --bg: #ECECEC;
  --line: #DBDBDB;
  --card: #FFFFFF;
  --alert: #C8402A;
  --shadow: 0 6px 20px rgba(6, 17, 60, 0.10);
  --shadow-up: 0 -8px 24px rgba(6, 17, 60, 0.12);
  --r-card: 16px;
  --r-pill: 999px;
  --font: "Pragmatica", "Golos Text", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }   /* the hidden attribute must win over display:flex/grid rules */
html, body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--ink);
  font: 500 15px/1.4 var(--font);
  font-feature-settings: "tnum" 1;
  -webkit-tap-highlight-color: transparent;
  -webkit-font-smoothing: antialiased;
}
button, input, select { font: inherit; color: inherit; }
button { cursor: pointer; }
:focus-visible { outline: 3px solid var(--orange); outline-offset: 2px; }
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: 0.01ms !important; transition-duration: 0.01ms !important; }
}

.app { display: flex; flex-direction: column; height: 100%; overflow: hidden; }

/* ---------- opening animation ---------- */
#intro {
  position: fixed; inset: 0; z-index: 100; overflow: hidden;
  background: linear-gradient(180deg, #F8F8FA 0%, #F1F1F3 38%, var(--bg) 56%, var(--bg) 100%);
  transition: opacity .5s ease, transform .5s ease;
}
#intro.out { opacity: 0; transform: scale(1.04); pointer-events: none; }
#intro canvas { position: absolute; inset: 0; width: 100%; height: 100%; display: block; }
#intro.static canvas { display: none; }
.intro-skip {
  position: absolute; top: calc(12px + env(safe-area-inset-top, 0px)); right: 14px; z-index: 2;
  border: 1px solid var(--line); background: rgba(255,255,255,.85); color: var(--muted); border-radius: var(--r-pill);
  padding: 6px 12px; font-size: 12.5px; font-weight: 600;
}
.intro-brand {
  position: absolute; left: 0; right: 0; bottom: calc(40px + var(--safe-bottom)); z-index: 2; text-align: center;
  opacity: 0; transform: translateY(10px); transition: opacity .6s ease, transform .6s ease; pointer-events: none;
}
.intro-brand.show, #intro.static .intro-brand { opacity: 1; transform: none; }
#intro.static .intro-brand { bottom: 50%; transform: translateY(50%); }
.intro-brand img { width: 44px; height: 54px; object-fit: contain; display: block; margin: 0 auto 8px; }
.intro-word { font-size: 14px; font-weight: 700; letter-spacing: .22em; color: var(--navy); }
.intro-bar { width: 140px; height: 3px; border-radius: 2px; background: var(--line); margin: 12px auto 0; overflow: hidden; }
.intro-bar i { display: block; height: 100%; background: var(--orange); transform-origin: left; transform: scaleX(0); transition: transform .3s linear; }

/* ---------- app bar ---------- */
.appbar {
  flex: none; display: flex; align-items: center; gap: 10px; padding: 10px 14px;
  background: var(--navy); color: #fff;
}
.appbar .mark { width: 36px; height: 44px; object-fit: contain; flex: none; }
.appbar .live-pill { margin-left: auto; }
.appbar .title { flex: 1; min-width: 0; line-height: 1.15; }
.appbar .title b { display: block; font-weight: 700; font-size: 16px; letter-spacing: .01em; }
.appbar .title span { display: block; font-size: 12px; color: rgba(255, 255, 255, .7); font-weight: 500; }
.appbar .icon-btn {
  flex: none; width: 36px; height: 36px; border-radius: 50%; border: 1px solid rgba(255,255,255,.18);
  background: rgba(255,255,255,.08); color: #fff; display: grid; place-items: center; font-size: 16px;
}

/* live pill: orange pulse while the bus reports, grey when quiet */
.live-pill {
  flex: 0 1 auto; min-width: 0; display: inline-flex; align-items: center; gap: 7px; padding: 6px 11px; border-radius: var(--r-pill);
  background: rgba(255,255,255,.10); font-size: 12.5px; font-weight: 600; white-space: nowrap;
}
.live-pill .txt { overflow: hidden; text-overflow: ellipsis; }
.live-pill .dot { width: 8px; height: 8px; border-radius: 50%; background: rgba(255,255,255,.4); }
.live-pill.live { background: var(--orange); color: var(--navy); }
.live-pill.live .dot { background: var(--navy); animation: pulse 1.6s ease-out infinite; }
.live-pill.quiet { background: rgba(255,255,255,.14); color: #fff; }
.live-pill.quiet .dot { background: var(--alert); }
.live-pill .ago { font-weight: 500; opacity: .85; }
/* floating over the map (parent page has no app bar) */
.live-pill.on-map {
  position: absolute; top: 12px; left: 12px; z-index: 10; max-width: calc(100% - 80px);
  background: var(--navy); color: #fff; box-shadow: var(--shadow); padding: 8px 13px;
}
.live-pill.on-map .dot { background: rgba(255,255,255,.5); }
.live-pill.on-map.live { background: var(--orange); color: var(--navy); }
.live-pill.on-map.live .dot { background: var(--navy); }
.live-pill.on-map.quiet { background: var(--card); color: var(--ink); }
.live-pill.on-map.quiet .dot { background: var(--alert); }
@keyframes pulse { 0% { box-shadow: 0 0 0 0 rgba(6,17,60,.45); } 70% { box-shadow: 0 0 0 7px rgba(6,17,60,0); } 100% { box-shadow: 0 0 0 0 rgba(6,17,60,0); } }

/* ---------- line chips ---------- */
.chips {
  flex: none; display: flex; gap: 8px; padding: 10px 14px; overflow-x: auto; scrollbar-width: none;
  background: var(--bg);
}
.chips::-webkit-scrollbar { display: none; }
.chip {
  flex: none; display: inline-flex; align-items: center; gap: 7px; padding: 8px 14px; border-radius: var(--r-pill);
  border: 1px solid var(--line); background: var(--card); color: var(--ink); font-weight: 600; font-size: 14px;
  white-space: nowrap; transition: background .15s, color .15s, border-color .15s;
}
.chip .mini-bus { width: 18px; height: 12px; display: none; }
.chip.live .mini-bus { display: block; }
.chip.active { background: var(--navy); color: #fff; border-color: var(--navy); }
.chip.active.live .mini-bus rect:first-child { fill: var(--orange); }

/* ---------- map ---------- */
.map-wrap { position: relative; flex: 1 1 auto; min-height: 200px; background: var(--line); }
#map { position: absolute; inset: 0; z-index: 0; }
.map-fabs { position: absolute; right: 12px; bottom: 14px; z-index: 10; display: flex; flex-direction: column; gap: 10px; }
.fab {
  width: 46px; height: 46px; border-radius: 50%; border: 1px solid var(--line); background: var(--card); color: var(--navy);
  box-shadow: var(--shadow); display: grid; place-items: center; font-weight: 700; font-size: 13px; letter-spacing: .02em;
  transition: background .15s, color .15s, transform .15s;
}
.fab:active { transform: scale(.94); }
.fab.on { background: var(--orange); color: var(--navy); border-color: var(--orange); }
.fab svg { width: 22px; height: 22px; }
.map-attrib-space { height: 18px; }

/* ---------- bottom sheet ---------- */
.sheet {
  flex: none; position: relative; z-index: 20; background: var(--card); border-radius: 22px 22px 0 0;
  box-shadow: var(--shadow-up); padding: 0 16px calc(14px + var(--safe-bottom));
  max-height: min(72%, calc(100% - 200px)); display: flex; flex-direction: column; transition: height .28s cubic-bezier(.2,.8,.2,1);
  overflow: hidden;
}
/* the handle is the only drag surface; a generous hit area around the 44px bar */
.sheet .handle {
  flex: none; width: 96px; height: 26px; margin: 2px auto 0; display: grid; place-items: center;
  touch-action: none; cursor: grab;
}
.sheet .handle::after { content: ""; width: 44px; height: 5px; border-radius: 3px; background: var(--line); }
.sheet .scroll {
  flex: 1 1 auto; min-height: 0;   /* must not grow past the sheet, or the last items can never be scrolled to */
  overflow-y: auto; touch-action: pan-y; overscroll-behavior: contain; padding-bottom: 10px; -webkit-overflow-scrolling: touch;
}
.eyebrow { font-size: 11px; font-weight: 700; letter-spacing: .12em; text-transform: uppercase; color: var(--muted); }

.hero { display: flex; align-items: flex-end; justify-content: space-between; gap: 12px; padding: 6px 0 10px; }
.hero .what { min-width: 0; }
.hero .stop-name { font-size: 20px; font-weight: 700; line-height: 1.2; margin-top: 3px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.hero .sub { color: var(--muted); font-size: 13px; margin-top: 3px; }
.hero .eta { text-align: right; flex: none; }
.hero .eta .num { font-size: 40px; font-weight: 700; line-height: 1; color: var(--orange-deep); letter-spacing: -.02em; }
.hero .eta .unit { font-size: 13px; font-weight: 600; color: var(--muted); margin-top: 2px; }
.hero .eta.idle .num { color: var(--navy); font-size: 22px; }
.hero.passed .eta .num { color: var(--muted); }

/* timeline of stops */
.timeline { list-style: none; margin: 4px 0 0; padding: 0; }
.timeline li {
  display: grid; grid-template-columns: 26px 1fr auto; align-items: center; column-gap: 12px; min-height: 44px;
  position: relative; border-radius: 10px;
}
.timeline .rail {
  position: relative; width: 26px; height: 100%; min-height: 44px; display: grid; place-items: center;
}
.timeline .rail::before { content: ""; position: absolute; left: 50%; top: 0; bottom: 0; width: 3px; margin-left: -1.5px; background: var(--line); }
.timeline li:first-child .rail::before { top: 50%; }
.timeline li:last-child .rail::before { bottom: 50%; }
.timeline li.passed .rail::before { background: var(--line); }
.timeline li.next .rail::before, .timeline li.upcoming .rail::before { background: var(--navy); }
.timeline li.passed + li.next .rail::before, .timeline li.passed + li.upcoming .rail::before {
  background: linear-gradient(var(--line) 50%, var(--navy) 50%);
}
.timeline .node {
  position: relative; z-index: 1; width: 14px; height: 14px; border-radius: 50%; background: var(--card);
  border: 3px solid var(--navy);
}
.timeline li.passed .node { border-color: var(--line); background: var(--line); }
.timeline li.next .node { width: 20px; height: 20px; border-color: var(--orange); background: var(--orange); box-shadow: 0 0 0 4px var(--orange-soft); }
.timeline li.school .node { border-radius: 4px; }
.timeline li.mine .node { border-color: var(--orange-deep); }
.timeline .name { font-weight: 600; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.timeline li.passed .name { color: var(--muted); font-weight: 500; }
.timeline .tag {
  display: inline-block; margin-left: 8px; font-size: 10.5px; font-weight: 700; letter-spacing: .06em; text-transform: uppercase;
  padding: 2px 7px; border-radius: var(--r-pill); background: var(--orange-soft); color: var(--orange-deep); vertical-align: 2px;
}
.timeline .eta { font-weight: 700; color: var(--navy); white-space: nowrap; }
.timeline li.passed .eta { color: var(--muted); font-weight: 500; }
.timeline li.next .eta { color: var(--orange-deep); }

.empty-card {
  display: flex; gap: 14px; align-items: center; padding: 14px 0 6px;
}
.empty-card > div:last-child { min-width: 0; }
.empty-card .ico { width: 54px; height: 54px; border-radius: 16px; background: var(--bg); display: grid; place-items: center; flex: none; }
.empty-card .ico svg { width: 34px; }
.empty-card b { display: block; font-size: 16px; }
.empty-card p { margin: 3px 0 0; color: var(--muted); font-size: 13.5px; }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px; min-height: 44px; padding: 0 18px;
  border: none; border-radius: 14px; background: var(--orange); color: var(--navy); font-weight: 700; font-size: 15px;
  box-shadow: 0 2px 0 var(--orange-deep); transition: transform .12s, box-shadow .12s;
}
.btn:active { transform: translateY(2px); box-shadow: none; }
.btn.navy { background: var(--navy); color: #fff; box-shadow: 0 2px 0 #020a2a; }
.btn.ghost { background: var(--card); color: var(--navy); border: 1px solid var(--line); box-shadow: none; }
.btn.danger { background: var(--alert); color: #fff; box-shadow: 0 2px 0 #96301f; }
.btn.small { min-height: 36px; padding: 0 13px; font-size: 13.5px; border-radius: 11px; }
.btn.block { width: 100%; }
.btn[disabled] { opacity: .5; pointer-events: none; }

.line-picker { display: flex; flex-direction: column; gap: 10px; margin: 6px 0 12px; }
.line-picker .btn { justify-content: flex-start; min-height: 52px; font-size: 16px; }
.line-picker .btn .mini-bus { width: 24px; height: 16px; display: block; }
.action-row { display: flex; gap: 10px; margin-top: 10px; }
.action-row .btn { flex: 1; }

.toast {
  position: fixed; left: 50%; bottom: calc(24px + var(--safe-bottom)); transform: translateX(-50%); z-index: 60;
  background: var(--navy); color: #fff; padding: 10px 16px; border-radius: var(--r-pill); font-size: 14px; font-weight: 600;
  box-shadow: var(--shadow); max-width: calc(100vw - 32px); text-align: center;
}
.toast.error { background: var(--alert); }
.credits { color: var(--muted); font-size: 8.5px; text-align: center; padding: 10px 0 0; opacity: .55; letter-spacing: .01em; }
.center-msg { padding: 40px 24px; text-align: center; color: var(--muted); }
.center-msg b { display: block; color: var(--ink); font-size: 17px; margin-bottom: 6px; }

/* ---------- map markers ---------- */
/* The bus: an isometric SVG that rotates to the heading; the shadow and pulse stay level. */
.bus-marker { position: relative; width: 64px; height: 64px; }
.bus-marker .pulse {
  position: absolute; left: 50%; top: 50%; width: 56px; height: 56px; margin: -28px 0 0 -28px; border-radius: 50%;
  background: var(--orange); opacity: .26; animation: bus-breathe 3.2s ease-in-out infinite;
}
.bus-marker.quiet .pulse { animation: none; opacity: .12; }
.bus-marker .shadow {
  position: absolute; left: 50%; top: 50%; width: 40px; height: 26px; margin: -10px 0 0 -20px; border-radius: 50%;
  background: rgba(6,17,60,.28); filter: blur(5px);
}
.bus-marker .body {
  position: absolute; inset: 0; display: grid; place-items: center;
  filter: drop-shadow(0 3px 3px rgba(6,17,60,.25));
}
.bus-marker .body svg { width: 60px; height: 60px; }
/* the map library positions .speed-anchor; the visible pill floats above the bus */
.speed-anchor { width: 0; height: 0; position: relative; }
.speed-tag {
  position: absolute; left: 0; bottom: 46px; transform: translateX(-50%);
  padding: 4px 10px; border-radius: var(--r-pill); background: var(--navy); color: #fff;
  font: 700 12px/1.2 var(--font); white-space: nowrap; box-shadow: 0 2px 6px rgba(6,17,60,.3);
}
.speed-tag::after {
  content: ""; position: absolute; left: 50%; bottom: -5px; margin-left: -5px; border: 5px solid transparent;
  border-top-color: var(--navy); border-bottom: 0;
}
.speed-tag[hidden] { display: none; }
.maplibregl-ctrl-top-right { top: 10px; right: 10px; }
.maplibregl-ctrl-group { border-radius: 50% !important; box-shadow: var(--shadow) !important; }
.maplibregl-ctrl-group button { width: 40px; height: 40px; border-radius: 50% !important; }
.bus-marker.quiet .body { filter: grayscale(1) opacity(.75); }
@keyframes bus-breathe { 0%, 100% { transform: scale(1); opacity: .26; } 50% { transform: scale(1.22); opacity: .14; } }

.stop-pill {
  min-width: 26px; height: 26px; padding: 0 7px; border-radius: 13px; display: grid; place-items: center;
  background: var(--card); color: var(--navy); border: 2.5px solid var(--navy); font: 700 12px/1 var(--font);
  box-shadow: 0 2px 6px rgba(6,17,60,.25); white-space: nowrap;
  transition: transform .15s, background .15s;
}
.stop-pill.passed { border-color: var(--line); color: var(--muted); box-shadow: none; }
.stop-pill.mine { background: var(--orange); border-color: var(--orange-deep); color: var(--navy); transform: scale(1.12); }
.stop-pill.next { box-shadow: 0 0 0 5px var(--orange-soft), 0 2px 6px rgba(6,17,60,.25); }
.stop-pill.draggable { cursor: grab; }
.school-pin { width: 40px; height: 48px; display: grid; place-items: center; filter: drop-shadow(0 3px 4px rgba(6,17,60,.3)); }
.school-pin img { width: 34px; height: 42px; object-fit: contain; }
.school-pin.passed { opacity: .55; }
.waypoint {
  width: 16px; height: 16px; border-radius: 50%; background: var(--orange); border: 3px solid var(--card);
  box-shadow: 0 1px 4px rgba(6,17,60,.35); cursor: grab;
}
.waypoint.stop { background: var(--navy); }
.track-pin { width: 14px; height: 14px; border-radius: 50%; border: 3px solid #fff; box-shadow: 0 1px 4px rgba(6,17,60,.35); }
.track-pin.start { background: var(--navy); }
.track-pin.end { background: var(--orange); }
.map-pin { background: none; border: none; overflow: visible; }
.leaflet-container { background: var(--line); font: inherit; }
.maplibregl-marker { cursor: pointer; }
.maplibregl-ctrl-attrib { font-size: 10px; }

/* ---------- admin ---------- */
.admin-tabs {
  flex: none; display: flex; gap: 4px; margin: 10px 14px 0; padding: 4px; background: var(--line); border-radius: 14px;
  overflow-x: auto; scrollbar-width: none;
}
.admin-tabs::-webkit-scrollbar { display: none; }
.admin-tabs button {
  flex: 1 0 auto; padding-left: 10px; padding-right: 10px; border: none; border-radius: 11px; padding: 9px 4px; background: transparent; color: var(--muted);
  font-weight: 600; font-size: 13px; white-space: nowrap;
}
.admin-tabs button.active { background: var(--card); color: var(--navy); box-shadow: 0 1px 4px rgba(6,17,60,.12); }
.admin-map { height: 44vh; min-height: 240px; position: relative; flex: none; margin: 10px 14px 0; border-radius: var(--r-card); overflow: hidden; box-shadow: var(--shadow); }
.admin-map #map { position: absolute; inset: 0; z-index: 0; }
.admin-map .map-fabs { bottom: 12px; }
.section { padding: 12px 14px calc(28px + var(--safe-bottom)); overflow-y: auto; flex: 1 1 auto; }
.card { background: var(--card); border-radius: var(--r-card); padding: 14px; margin-bottom: 10px; box-shadow: 0 1px 3px rgba(6,17,60,.06); }
.card h3 { margin: 0 0 8px; font-size: 15px; }
.row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.row + .row { margin-top: 10px; }
.grow { flex: 1 1 140px; min-width: 0; }
input[type="text"], select {
  width: 100%; min-height: 42px; padding: 8px 12px; border-radius: 12px; border: 1px solid var(--line); background: var(--bg);
  font-weight: 500;
}
input[type="text"]:focus, select:focus { outline: none; border-color: var(--orange); background: var(--card); }
input[type="color"] { width: 42px; height: 42px; border: none; background: none; padding: 0; border-radius: 10px; }
.hint { color: var(--muted); font-size: 13px; margin: 0 0 10px; line-height: 1.45; }
.link-box { word-break: break-all; font-size: 13px; background: var(--bg); padding: 10px; border-radius: 10px; margin: 8px 0; font-weight: 500; }
.stop-row { display: flex; gap: 6px; align-items: center; margin-bottom: 8px; }
.stop-row .num { width: 24px; text-align: center; color: var(--muted); flex: none; font-weight: 700; font-size: 13px; }
.trip { cursor: pointer; transition: box-shadow .15s; }
.trip.selected { box-shadow: 0 0 0 2px var(--orange); }
.trip.picked { box-shadow: 0 0 0 2px var(--alert); }
.trip .sub { color: var(--muted); font-size: 13px; margin-top: 4px; }
.pill {
  display: inline-block; font-size: 11.5px; font-weight: 700; padding: 3px 9px; border-radius: var(--r-pill);
  background: var(--bg); color: var(--navy); margin-right: 6px;
}
.pill.orange { background: var(--orange-soft); color: var(--orange-deep); }
.pill.navy { background: var(--navy); color: #fff; }
.status-badge { display: inline-flex; align-items: center; gap: 6px; font-size: 12.5px; font-weight: 700; color: var(--orange-deep); }
.status-badge::before { content: ""; width: 8px; height: 8px; border-radius: 50%; background: var(--orange); animation: pulse 1.6s infinite; }
label.check { display: inline-flex; align-items: center; gap: 8px; font-weight: 600; }
label.check input { width: 18px; height: 18px; accent-color: var(--orange-deep); }
