@import url('https://fonts.googleapis.com/css2?family=Fraunces:opsz,wght@9..144,400;9..144,500;9..144,600&family=Manrope:wght@400;500;600;700&display=swap');

:root {
  --color-bg: #f3f5f2;
  --color-bg-elevated: #ffffff;
  --color-ink: #1d2b2e;
  --color-ink-soft: #51625f;
  --color-accent: #e8a33d;
  --color-accent-deep: #a56a1a;
  --color-go: #2f7d5c;
  --color-go-bg: #e4f1ea;
  --color-alert: #b23a3a;
  --color-alert-bg: #f7e6e4;
  --color-chrome: #16232c;
  --color-chrome-soft: #24333d;
  --color-border: #dde3dc;
  --font-display: 'Fraunces', 'Georgia', serif;
  --font-body: 'Manrope', -apple-system, BlinkMacSystemFont, sans-serif;
  --radius-s: 8px;
  --radius-m: 14px;
  --shadow-card: 0 1px 2px rgba(29, 43, 46, 0.06), 0 6px 20px rgba(29, 43, 46, 0.06);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
}

body {
  background: var(--color-bg);
  color: var(--color-ink);
  font-family: var(--font-body);
  font-size: 16px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

h1, h2, h3 {
  font-family: var(--font-display);
  font-weight: 600;
  margin: 0 0 0.4em;
  letter-spacing: -0.01em;
}

p { margin: 0 0 1em; color: var(--color-ink-soft); }

a { color: var(--color-accent-deep); }

button, input, select {
  font-family: inherit;
  font-size: inherit;
}

:focus-visible {
  outline: 2px solid var(--color-accent-deep);
  outline-offset: 2px;
}

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

/* ---------- layout ---------- */

.app-shell {
  display: flex;
  flex-direction: column;
  min-height: 100vh;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 20px;
  background: var(--color-chrome);
  color: #fff;
}

.topbar .wordmark {
  font-family: var(--font-display);
  font-size: 19px;
  font-weight: 600;
  color: #fff;
  text-decoration: none;
  letter-spacing: -0.01em;
}

.topbar .wordmark span { color: var(--color-accent); }

.topbar-meta {
  display: flex;
  align-items: center;
  gap: 14px;
  font-size: 14px;
  color: #c7d2ce;
}

.topbar-meta button {
  background: transparent;
  border: 1px solid #3a4a53;
  color: #fff;
  padding: 7px 14px;
  border-radius: var(--radius-s);
  cursor: pointer;
}
.topbar-meta button:hover { background: var(--color-chrome-soft); }

.container {
  max-width: 1100px;
  margin: 0 auto;
  padding: 24px 20px 60px;
  width: 100%;
}

/* ---------- buttons + forms ---------- */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  border: none;
  border-radius: var(--radius-s);
  padding: 11px 18px;
  font-weight: 600;
  font-size: 15px;
  cursor: pointer;
  transition: transform 0.08s ease, background 0.15s ease;
}
.btn:active { transform: scale(0.98); }

.btn-primary { background: var(--color-accent); color: #33230a; }
.btn-primary:hover { background: #dc9530; }

.btn-secondary { background: var(--color-bg-elevated); color: var(--color-ink); border: 1px solid var(--color-border); }
.btn-secondary:hover { border-color: var(--color-ink-soft); }

.btn-danger { background: var(--color-alert-bg); color: var(--color-alert); }
.btn-danger:hover { background: #f0d3d0; }

.btn-block { width: 100%; }
.btn[disabled] { opacity: 0.55; cursor: not-allowed; }

.field { margin-bottom: 16px; }
.field label {
  display: block;
  font-size: 13px;
  font-weight: 600;
  color: var(--color-ink-soft);
  margin-bottom: 6px;
}
.field input, .field select {
  width: 100%;
  padding: 11px 13px;
  border: 1px solid var(--color-border);
  border-radius: var(--radius-s);
  background: #fff;
  color: var(--color-ink);
}
.field input:focus, .field select:focus { border-color: var(--color-accent-deep); }
.field-row { display: flex; gap: 12px; }
.field-row .field { flex: 1; }

.error-text { color: var(--color-alert); font-size: 14px; margin: -6px 0 14px; min-height: 1.2em; }

/* ---------- login ---------- */

.auth-screen {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--color-chrome);
  padding: 20px;
}

.auth-card {
  width: 100%;
  max-width: 380px;
  background: var(--color-bg-elevated);
  border-radius: var(--radius-m);
  padding: 36px 32px;
  box-shadow: var(--shadow-card);
}

.auth-card h1 {
  font-size: 28px;
  margin-bottom: 4px;
}
.auth-card h1 span { color: var(--color-accent-deep); }
.auth-card .subhead { color: var(--color-ink-soft); font-size: 14px; margin-bottom: 26px; }

.role-toggle {
  display: flex;
  border: 1px solid var(--color-border);
  border-radius: var(--radius-s);
  padding: 3px;
  margin-bottom: 20px;
}
.role-toggle button {
  flex: 1;
  border: none;
  background: transparent;
  padding: 8px;
  border-radius: 6px;
  font-size: 13px;
  font-weight: 600;
  color: var(--color-ink-soft);
  cursor: pointer;
}
.role-toggle button.active { background: var(--color-bg); color: var(--color-ink); }

/* ---------- status pills ---------- */

.pill {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 5px 12px;
  border-radius: 999px;
  font-size: 13px;
  font-weight: 600;
}
.pill-go { background: var(--color-go-bg); color: var(--color-go); }
.pill-wait { background: #f3ecd9; color: var(--color-accent-deep); }
.pill-alert { background: var(--color-alert-bg); color: var(--color-alert); }
.pill-dot { width: 7px; height: 7px; border-radius: 50%; background: currentColor; }

/* ---------- parent dashboard ---------- */

.parent-layout {
  display: grid;
  grid-template-columns: 1fr;
  gap: 0;
  flex: 1;
}
@media (min-width: 900px) {
  .parent-layout { grid-template-columns: 1.3fr 1fr; align-items: stretch; }
}

#map {
  width: 100%;
  min-height: 320px;
  background: #dfe6e0;
}
@media (min-width: 900px) { #map { height: calc(100vh - 60px); } }

#liveMap {
  width: 100%;
  height: 420px;
  background: #dfe6e0;
}

.parent-side {
  padding: 22px 20px 40px;
  overflow-y: auto;
}

.child-card {
  background: var(--color-bg-elevated);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-m);
  padding: 18px;
  margin-bottom: 14px;
  cursor: pointer;
}
.child-card.selected { border-color: var(--color-accent); box-shadow: 0 0 0 1px var(--color-accent); }

.child-card-top {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  margin-bottom: 10px;
}
.child-card h3 { font-size: 17px; margin: 0; }
.child-card .stop-name { font-size: 13px; color: var(--color-ink-soft); margin-top: 2px; }

.eta-hero {
  font-family: var(--font-display);
  font-size: 44px;
  line-height: 1;
  font-weight: 600;
  color: var(--color-ink);
  margin: 4px 0 2px;
  font-variant-numeric: tabular-nums;
}
.eta-hero .unit { font-size: 16px; font-family: var(--font-body); font-weight: 600; color: var(--color-ink-soft); margin-left: 4px; }
.eta-hero.eta-word { font-size: 34px; } /* "Arrived" / "At school" are words, not numbers - a bit smaller so they never crowd the card */
.eta-sub { font-size: 13px; color: var(--color-ink-soft); }

.empty-state {
  text-align: center;
  padding: 60px 20px;
  color: var(--color-ink-soft);
}

/* ---------- admin ---------- */

.tabs {
  display: flex;
  gap: 4px;
  border-bottom: 1px solid var(--color-border);
  margin-bottom: 22px;
  flex-wrap: wrap;
}
.tabs button {
  border: none;
  background: none;
  padding: 11px 16px;
  font-size: 14px;
  font-weight: 600;
  color: var(--color-ink-soft);
  cursor: pointer;
  border-bottom: 2px solid transparent;
  margin-bottom: -1px;
}
.tabs button.active { color: var(--color-ink); border-bottom-color: var(--color-accent); }

.panel {
  background: var(--color-bg-elevated);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-m);
  padding: 22px;
  margin-bottom: 20px;
}
.panel-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 16px;
}
.panel-head h2 { font-size: 19px; margin: 0; }

table { width: 100%; border-collapse: collapse; font-size: 14px; }
th, td { text-align: left; padding: 10px 8px; border-bottom: 1px solid var(--color-border); }
th { color: var(--color-ink-soft); font-weight: 600; font-size: 12.5px; text-transform: none; }
tr:last-child td { border-bottom: none; }
td.actions { text-align: right; white-space: nowrap; }
td.actions button { margin-left: 6px; }

.stop-row {
  display: flex;
  gap: 8px;
  align-items: center;
  margin-bottom: 8px;
}
.stop-row .field { margin-bottom: 0; flex: 1; }
.stop-row .field.coords { flex: 0 0 210px; display: flex; gap: 6px; }
.stop-row .field.coords input { width: 100%; }

.stop-order {
    padding: 0 5px;
    border: 1px solid silver;
    height: min-content;
    border-radius: 999px;
    background: #2e84cb;
    color: white;
}

.mainstop .stop-move { display: flex; flex-direction: column; gap: 2px; }
.mainstop .stop-move button { padding: 2px 8px; font-size: 10px; line-height: 1.4; }

.mainstop {
  display: flex;
  gap: 7px;
}

#stopPickerMap {
  height: 260px;
  border-radius: var(--radius-s);
  margin: 10px 0 16px;
  border: 1px solid var(--color-border);
}

.hint { font-size: 12.5px; color: var(--color-ink-soft); margin-top: -8px; margin-bottom: 14px; }

.modal-backdrop {
  position: fixed; inset: 0; background: rgba(22, 35, 44, 0.45);
  display: flex; align-items: center; justify-content: center; padding: 20px; z-index: 40;
}
.modal {
  background: #fff; border-radius: var(--radius-m); padding: 26px;
  width: 100%; max-width: 780px; max-height: 90vh; overflow-y: auto;
}
.modal h2 { font-size: 19px; margin-bottom: 18px; }

.leaflet-marker-icon.bus-marker { filter: drop-shadow(0 2px 3px rgba(0,0,0,0.3)); }

/* Admin: each bus has its own colour - the dot in the tables and the name tag beside its map marker */
.bus-dot {
  display: inline-block; width: 12px; height: 12px; margin-right: 8px; vertical-align: -1px;
  border-radius: 50%; border: 2px solid #fff; box-shadow: 0 0 0 1px rgba(29, 43, 46, 0.3);
}
.leaflet-tooltip.bus-tag { background: transparent; border: 0; box-shadow: none; padding: 0; }
.leaflet-tooltip.bus-tag::before { display: none; }
.bus-tag-text {
  display: block; max-width: 180px; padding: 2px 8px; overflow: hidden; text-overflow: ellipsis;
  white-space: nowrap; border: 2px solid #fff; border-radius: 999px;
  font-size: 12px; font-weight: 700; line-height: 1.3; box-shadow: 0 1px 3px rgba(0, 0, 0, 0.35);
}

/* Admin: the route of a bus on a trip, in the bus's colour - stops ticked once reached, the next one ringed */
.stop-marker { display: flex; align-items: center; justify-content: center; background: none; border: 0; }
.stop-pin {
  --c: #51625f; --ink: #fff; --halo: rgba(81, 98, 95, 0.3);
  display: flex; align-items: center; justify-content: center; box-sizing: border-box;
  width: 22px; height: 22px; border: 3px solid var(--c); border-radius: 50%;
  background: #fff; color: #1d2b2e; font-size: 11px; font-weight: 800; line-height: 1;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.4);
}
.stop-pin.is-school { border-radius: 6px; }
.stop-pin.is-reached { background: var(--c); color: var(--ink); }
.stop-pin.is-next {
  width: 30px; height: 30px; font-size: 13px;
  box-shadow: 0 0 0 5px var(--halo), 0 1px 4px rgba(0, 0, 0, 0.45);
  animation: stop-pulse 1.8s ease-out infinite;
}
.stop-pin svg { width: 12px; height: 12px; fill: currentColor; }
@keyframes stop-pulse {
  0% { box-shadow: 0 0 0 0 var(--halo), 0 1px 4px rgba(0, 0, 0, 0.45); }
  70% { box-shadow: 0 0 0 12px rgba(0, 0, 0, 0), 0 1px 4px rgba(0, 0, 0, 0.45); }
  100% { box-shadow: 0 0 0 0 rgba(0, 0, 0, 0), 0 1px 4px rgba(0, 0, 0, 0.45); }
}
/* zoomed far out the stops of a route overlap: plain dots, except the next stop */
.stops-compact .stop-pin:not(.is-next) { width: 12px; height: 12px; border-width: 2px; font-size: 0; }
.stops-compact .stop-pin:not(.is-next) svg { display: none; }
.stops-compact .stop-pin.is-school:not(.is-next) { border-radius: 3px; }

.leaflet-tooltip.stop-tag { background: transparent; border: 0; box-shadow: none; padding: 0; }
.leaflet-tooltip.stop-tag::before { display: none; }
/* a long stop name is cut short, never the ETA after it */
.stop-tag-text {
  display: flex; gap: 4px; max-width: 260px; padding: 2px 9px; overflow: hidden;
  white-space: nowrap; border: 2px solid; border-radius: 999px; background: #fff; color: #1d2b2e;
  font-size: 12px; font-weight: 600; line-height: 1.3; box-shadow: 0 1px 3px rgba(0, 0, 0, 0.35);
}
.stop-tag-text b { flex: none; font-weight: 800; }
.stop-tag-name { min-width: 0; overflow: hidden; text-overflow: ellipsis; }
.stop-tag-eta { flex: none; }

.stop-popup .leaflet-popup-content { margin: 12px 14px; font-family: var(--font-body); }
.stop-pop { min-width: 190px; max-width: 250px; }
.stop-pop-title { font-size: 15px; font-weight: 700; line-height: 1.3; }
.stop-pop-title .bus-dot { margin-right: 6px; }
.stop-pop-sub { margin-top: 2px; font-size: 12px; color: var(--color-ink-soft); }
.stop-pop-state { margin-top: 8px; font-size: 13px; font-weight: 700; }
.stop-pop-label { margin: 10px 0 2px; font-size: 12px; font-weight: 700; color: var(--color-ink-soft); }
.stop-pop .stop-none { margin: 10px 0 0; font-size: 12.5px; }
.stop-kids { margin: 0; padding: 0; list-style: none; max-height: 160px; overflow-y: auto; }
.stop-kids li { display: flex; justify-content: space-between; gap: 10px; padding: 4px 0; border-top: 1px solid var(--color-border); font-size: 13px; }
.stop-kids small { color: var(--color-ink-soft); }
.stop-kids em { font-size: 12px; font-style: normal; font-weight: 700; white-space: nowrap; }
.kid-ok { color: var(--color-go); }
.kid-absent { color: var(--color-alert); }
.kid-wait { color: var(--color-ink-soft); }

.map-legend {
  display: flex; flex-wrap: wrap; align-items: center; gap: 6px 18px; padding: 10px 16px;
  border-top: 1px solid var(--color-border); font-size: 12.5px; color: var(--color-ink-soft);
}
.map-legend span { display: inline-flex; align-items: center; gap: 6px; }
.legend-pin { display: inline-block; box-sizing: border-box; width: 14px; height: 14px; border: 2.5px solid #51625f; border-radius: 50%; background: #fff; }
.legend-pin.is-reached { background: #51625f; }
.legend-pin.is-school { border-radius: 4px; }
.legend-pin.is-next { width: 18px; height: 18px; box-shadow: 0 0 0 3px rgba(81, 98, 95, 0.3); }

.table-scroll { overflow-x: auto; }
tr.on-map { cursor: pointer; }
tr.on-map:hover td { background: #f7f9f6; }
.bus-link { padding: 0; border: 0; background: none; color: inherit; font: inherit; text-align: left; cursor: pointer; }
.cell-sub { margin-top: 2px; font-size: 12.5px; color: var(--color-ink-soft); }
