:root {
  --primary: #ffc528;
  --on-primary: #000;
  --success: #2e9e5b;
  --error: #d64545;

  --bg: #f4f4f2;
  --surface: #ffffff;
  --text: #111111;
  --text-2: #6b6b6b;
  --input: #f1f1ef;
  --divider: #e7e7e4;
  --shadow: 0 -8px 32px rgba(0, 0, 0, 0.12);
  --chip-shadow: 0 2px 12px rgba(0, 0, 0, 0.14);
  --route: #111111;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme='light']) {
    --bg: #0f0f0f;
    --surface: #1a1a1a;
    --text: #f5f5f5;
    --text-2: #a3a3a3;
    --input: #262626;
    --divider: #2c2c2c;
    --shadow: 0 -8px 32px rgba(0, 0, 0, 0.5);
    --chip-shadow: 0 2px 12px rgba(0, 0, 0, 0.5);
    --route: #ffc528;
  }
}

:root[data-theme='dark'] {
  --bg: #0f0f0f;
  --surface: #1a1a1a;
  --text: #f5f5f5;
  --text-2: #a3a3a3;
  --input: #262626;
  --divider: #2c2c2c;
  --shadow: 0 -8px 32px rgba(0, 0, 0, 0.5);
  --chip-shadow: 0 2px 12px rgba(0, 0, 0, 0.5);
  --route: #ffc528;
}

* {
  box-sizing: border-box;
}

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

body {
  background: var(--bg);
  color: var(--text);
  font-family: 'Rubik', system-ui, -apple-system, 'Segoe UI', sans-serif;
  -webkit-font-smoothing: antialiased;
  overflow: hidden;
}

p,
h1 {
  margin: 0;
}

[hidden] {
  display: none !important;
}

/* ---- map ---------------------------------------------------------------- */

#map {
  /* !important: Google Maps sets position: relative on its container,
     which would collapse it to zero height */
  position: fixed !important;
  inset: 0;
  background: var(--bg);
}

/* no key, a refused key or no connection to Google: say so in place of
   the map — the trip details in the sheet still work */
.map-unavailable::after {
  content: attr(data-message);
  position: absolute;
  inset: 0 0 var(--sheet-height, 280px);
  display: grid;
  place-items: center;
  padding: 24px;
  text-align: center;
  color: var(--text-2);
  font-size: 14px;
}

.car-marker {
  width: 44px;
  height: 44px;
  border-radius: 50%;
  background: var(--primary);
  color: var(--on-primary);
  display: grid;
  place-items: center;
  border: 3px solid #fff;
  box-shadow: 0 4px 14px rgba(0, 0, 0, 0.3);
}

.pin {
  width: 18px;
  height: 18px;
  border: 3px solid #fff;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.3);
}

.pin-pickup {
  border-radius: 50%;
  background: var(--success);
}

.pin-dropoff {
  border-radius: 4px;
  background: #111;
}

/* ---- floating chrome ---------------------------------------------------- */

.brand {
  position: fixed;
  top: max(16px, env(safe-area-inset-top));
  left: 16px;
  z-index: 500;
  background: var(--surface);
  border-radius: 999px;
  padding: 10px 16px;
  box-shadow: var(--chip-shadow);
  display: flex;
  align-items: center;
}

.logo {
  height: 18px;
  width: auto;
  display: block;
}

.logo-dark {
  display: none;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme='light']) .logo-light {
    display: none;
  }
  :root:not([data-theme='light']) .logo-dark {
    display: block;
  }
}

.recenter {
  position: fixed;
  right: 16px;
  z-index: 500;
  bottom: calc(var(--sheet-height, 280px) + 16px);
  width: 48px;
  height: 48px;
  border-radius: 50%;
  border: 0;
  background: var(--surface);
  color: var(--text);
  box-shadow: var(--chip-shadow);
  display: grid;
  place-items: center;
  cursor: pointer;
}

.recenter:focus-visible {
  outline: 3px solid var(--primary);
  outline-offset: 2px;
}

/* ---- bottom sheet ------------------------------------------------------- */

.sheet {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 600;
  max-height: 70vh;
  overflow-y: auto;
  background: var(--surface);
  border-radius: 20px 20px 0 0;
  box-shadow: var(--shadow);
  padding: 10px 20px max(20px, env(safe-area-inset-bottom));
}

@media (min-width: 720px) {
  .sheet {
    left: 24px;
    right: auto;
    bottom: 24px;
    width: 400px;
    border-radius: 20px;
    max-height: calc(100vh - 120px);
  }
  .recenter {
    bottom: 24px;
  }
}

/* the grab handle: tap (or drag down/up) to shrink the sheet to its
   headline and see the map, then bring it back */
.sheet-toggle {
  display: block;
  width: 100%;
  height: 28px;
  margin: -10px 0 4px;
  padding: 0;
  border: 0;
  background: none;
  cursor: pointer;
  touch-action: none;
}

.sheet-toggle:focus-visible {
  outline: 3px solid var(--primary);
  outline-offset: -3px;
  border-radius: 12px;
}

.handle {
  display: block;
  width: 40px;
  height: 4px;
  border-radius: 2px;
  background: var(--divider);
  margin: 12px auto 0;
}

.sheet.collapsed #subline,
.sheet.collapsed #driver,
.sheet.collapsed .stops,
.sheet.collapsed #footnote {
  display: none !important;
}

.sheet.collapsed .headline {
  font-size: 18px;
}

@media (min-width: 720px) {
  .sheet-toggle {
    display: none;
  }
}

.status-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 10px;
}

.status {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 12px;
  font-weight: 600;
  padding: 5px 10px;
  border-radius: 999px;
  background: var(--input);
  color: var(--text);
}

.status::before {
  content: '';
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: currentColor;
}

.status.live {
  background: var(--primary);
  color: var(--on-primary);
}

.status.live::before {
  animation: pulse 1.6s ease-in-out infinite;
}

.status.done {
  background: rgba(46, 158, 91, 0.14);
  color: var(--success);
}

.status.cancelled {
  background: rgba(214, 69, 69, 0.12);
  color: var(--error);
}

@keyframes pulse {
  50% {
    opacity: 0.25;
  }
}

@media (prefers-reduced-motion: reduce) {
  .status.live::before,
  .spinner {
    animation: none !important;
  }
}

.connection {
  font-size: 12px;
  color: var(--text-2);
}

.headline {
  font-size: 22px;
  font-weight: 700;
  line-height: 1.2;
  letter-spacing: -0.01em;
}

.subline {
  margin-top: 4px;
  font-size: 14px;
  color: var(--text-2);
  line-height: 1.4;
}

.driver {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-top: 18px;
  padding: 12px;
  border-radius: 16px;
  background: var(--input);
}

.avatar {
  flex: none;
  width: 48px;
  height: 48px;
  border-radius: 50%;
  background: var(--primary);
  color: var(--on-primary);
  display: grid;
  place-items: center;
  overflow: hidden;
  font-weight: 700;
  font-size: 18px;
}

.avatar img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.driver-info {
  flex: 1;
  min-width: 0;
}

.driver-name {
  font-size: 15px;
  font-weight: 600;
}

.vehicle {
  margin-top: 2px;
  font-size: 13px;
  color: var(--text-2);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.plate {
  flex: none;
  font-size: 13px;
  font-weight: 700;
  letter-spacing: 0.04em;
  padding: 6px 10px;
  border-radius: 8px;
  background: var(--primary);
  color: var(--on-primary);
  white-space: nowrap;
}

.stops {
  list-style: none;
  margin: 18px 0 0;
  padding: 0;
  position: relative;
}

.stops::before {
  content: '';
  position: absolute;
  left: 5px;
  top: 16px;
  bottom: 30px;
  border-left: 2px dotted var(--divider);
}

.stop {
  display: flex;
  gap: 14px;
  align-items: flex-start;
}

.stop + .stop {
  margin-top: 14px;
}

.dot {
  flex: none;
  width: 12px;
  height: 12px;
  margin-top: 4px;
  position: relative;
}

.dot-pickup {
  border-radius: 50%;
  background: var(--success);
}

.dot-dropoff {
  border-radius: 3px;
  background: var(--text);
}

.stop-label {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-2);
}

.stop-address {
  margin-top: 2px;
  font-size: 14px;
  line-height: 1.35;
  overflow-wrap: anywhere;
}

.footnote {
  margin-top: 18px;
  padding-top: 14px;
  border-top: 1px solid var(--divider);
  font-size: 12px;
  color: var(--text-2);
  line-height: 1.4;
}

.footnote:empty {
  display: none;
}

/* ---- loading / error ---------------------------------------------------- */

.state {
  text-align: center;
  padding: 12px 0 8px;
}

.state p {
  color: var(--text-2);
  font-size: 14px;
}

.spinner {
  width: 32px;
  height: 32px;
  margin: 4px auto 12px;
  border-radius: 50%;
  border: 3px solid var(--input);
  border-top-color: var(--primary);
  animation: spin 0.9s linear infinite;
}

@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}

.error-icon {
  width: 56px;
  height: 56px;
  margin: 4px auto 14px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  background: var(--input);
  color: var(--text-2);
}
