:root {
  color-scheme: light;
  --bg: #f7fbf8;
  --panel: rgba(255, 255, 255, 0.94);
  --panel-solid: #ffffff;
  --ink: #14201c;
  --muted: #62706b;
  --line: rgba(25, 43, 36, 0.13);
  --brand: #0f6b5f;
  --brand-strong: #07473f;
  --accent: #f47321;
  --danger: #ba3a2b;
  --shadow: 0 18px 46px rgba(21, 42, 34, 0.22);
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --sheet-bottom-padding: 14px;
  --sheet-collapsed-height: calc(116px + var(--sheet-bottom-padding) + var(--safe-bottom));
}

* {
  box-sizing: border-box;
}

html,
body {
  width: 100%;
  height: 100%;
  margin: 0;
  background: var(--panel-solid);
}

body {
  overflow: hidden;
  color: var(--ink);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

button {
  color: inherit;
  font: inherit;
}

.app-shell,
.map {
  position: fixed;
  inset: 0;
}

.app-shell {
  background: var(--bg);
}

.map {
  z-index: 0;
  background: #dfe9e3;
}

.top-bar {
  position: fixed;
  z-index: 20;
  top: calc(10px + var(--safe-top));
  left: 10px;
  right: 10px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  pointer-events: none;
}

.identity {
  min-width: 0;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  box-shadow: 0 10px 30px rgba(24, 41, 35, 0.13);
  backdrop-filter: blur(14px);
  pointer-events: auto;
}

.identity-copy {
  min-width: 0;
  position: relative;
}

.identity-mark {
  width: 38px;
  height: 26px;
  flex: 0 0 auto;
  display: block;
  border: 1px solid rgba(20, 55, 49, 0.18);
  border-radius: 5px;
  background: var(--panel-solid);
  box-shadow: 0 1px 4px rgba(24, 41, 35, 0.16);
  object-fit: cover;
}

.status-text,
.eyebrow,
.selected-stop-meta,
.section-label,
.last-updated,
.eta-card p,
.eta-card span {
  margin: 0;
}

.system-picker {
  position: relative;
  display: inline-block;
  max-width: 210px;
}

.system-button {
  max-width: 210px;
  min-width: 0;
  display: inline-flex;
  align-items: center;
  gap: 7px;
  padding: 0;
  border: 0;
  border-radius: 4px;
  background: transparent;
  color: var(--ink);
  cursor: pointer;
  font-size: 15px;
  font-weight: 800;
  font-family: inherit;
  line-height: 1.1;
}

.system-button span {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.system-button::after {
  content: "";
  flex: 0 0 auto;
  width: 7px;
  height: 7px;
  border-right: 2px solid var(--brand);
  border-bottom: 2px solid var(--brand);
  transform: translateY(-1px) rotate(45deg);
  transition: transform 160ms ease;
}

.system-button[aria-expanded="true"]::after {
  transform: translateY(2px) rotate(225deg);
}

.system-button:focus-visible {
  outline: 2px solid rgba(15, 107, 95, 0.28);
  outline-offset: 2px;
}

.system-button:disabled {
  cursor: wait;
  opacity: 1;
}

.system-menu {
  position: absolute;
  z-index: 40;
  top: calc(100% + 14px);
  left: 0;
  min-width: 178px;
  display: grid;
  gap: 4px;
  padding: 6px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.96);
  box-shadow: 0 14px 34px rgba(24, 41, 35, 0.18);
  backdrop-filter: blur(18px);
}

.system-menu[hidden] {
  display: none;
}

.system-option {
  width: 100%;
  min-width: 0;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  height: 36px;
  padding: 0 10px;
  border: 0;
  border-radius: 7px;
  background: transparent;
  color: var(--ink);
  cursor: pointer;
  font-size: 14px;
  font-weight: 800;
  font-family: inherit;
  text-align: left;
  white-space: nowrap;
}

.system-option::after {
  content: "";
  width: 6px;
  height: 11px;
  flex: 0 0 auto;
  border-right: 2px solid currentColor;
  border-bottom: 2px solid currentColor;
  opacity: 0;
  transform: translateY(-1px) rotate(45deg);
}

.system-option.is-active {
  background: var(--brand);
  color: #ffffff;
}

.system-option.is-active::after {
  opacity: 1;
}

.system-option:focus-visible {
  outline: 2px solid rgba(15, 107, 95, 0.28);
  outline-offset: 2px;
}

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

.icon-button {
  display: inline-grid;
  width: 44px;
  height: 44px;
  place-items: center;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  box-shadow: 0 10px 30px rgba(24, 41, 35, 0.13);
  backdrop-filter: blur(14px);
  cursor: pointer;
  pointer-events: auto;
}

.icon-button svg {
  width: 22px;
  height: 22px;
  fill: none;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.icon-button:active,
.route-filter:active,
.nearby-stop:active {
  transform: translateY(1px);
}

.icon-button.quiet {
  width: 40px;
  height: 40px;
  box-shadow: none;
  background: #f4f8f5;
}

.route-filters {
  position: fixed;
  left: 10px;
  right: 10px;
  display: flex;
  gap: 8px;
  overflow-x: auto;
  padding-bottom: 8px;
  scrollbar-width: none;
}

.route-filters {
  z-index: 18;
  top: calc(74px + var(--safe-top));
}

.route-filters::-webkit-scrollbar {
  display: none;
}

.route-filter {
  min-width: max-content;
  display: flex;
  align-items: center;
  gap: 7px;
  height: 38px;
  padding: 0 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.78);
  color: var(--muted);
  box-shadow: 0 8px 24px rgba(24, 41, 35, 0.11);
  backdrop-filter: blur(14px);
  cursor: pointer;
  transition: background 160ms ease, border-color 160ms ease, color 160ms ease, opacity 160ms ease, transform 120ms ease;
}

.route-filter.is-active {
  background: var(--panel-solid);
  color: var(--ink);
  border-color: rgba(15, 107, 95, 0.22);
}

.route-filter.is-focused {
  background: var(--route-color);
  color: var(--route-text-color);
  border-color: rgba(20, 32, 28, 0.28);
  box-shadow: 0 12px 28px rgba(24, 41, 35, 0.2);
}

.route-filter.is-muted {
  opacity: 0.58;
}

.route-dot {
  width: 10px;
  height: 10px;
  flex: 0 0 auto;
  border-radius: 99px;
  box-shadow: 0 0 0 2px rgba(255, 255, 255, 0.9);
}

.route-filter.is-focused .route-dot {
  background: currentColor !important;
  box-shadow: 0 0 0 2px rgba(255, 255, 255, 0.48);
}

.route-dot.large {
  width: 14px;
  height: 14px;
}

.route-count {
  min-width: 20px;
  height: 20px;
  display: inline-grid;
  place-items: center;
  border-radius: 99px;
  background: #eef4ef;
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
}

.route-filter.is-focused .route-count {
  background: rgba(255, 255, 255, 0.28);
  color: currentColor;
}

.bottom-sheet {
  --sheet-drag-offset: 0px;
  position: fixed;
  z-index: 22;
  left: 0;
  right: 0;
  bottom: 0;
  height: auto;
  max-height: calc(100dvh - 98px - var(--safe-top));
  padding: 10px 14px var(--sheet-bottom-padding);
  border-radius: 18px 18px 0 0;
  background: var(--panel-solid);
  box-shadow: var(--shadow), 0 var(--safe-bottom) 0 var(--panel-solid);
  backdrop-filter: none;
  overflow: hidden;
  overscroll-behavior: contain;
  transform: translateY(var(--sheet-drag-offset));
  transition: max-height 180ms ease, height 180ms ease, transform 180ms ease;
}

.bottom-sheet.is-dragging {
  transition: none;
  user-select: none;
}

.bottom-sheet.is-expanded {
  height: calc(100dvh - 18px - var(--safe-top));
  max-height: calc(100dvh - 18px - var(--safe-top));
  padding-bottom: calc(14px + var(--safe-bottom));
  overflow-y: auto;
}

.bottom-sheet:not(.is-expanded) {
  cursor: pointer;
}

.sheet-handle {
  display: block;
  width: 52px;
  height: 22px;
  margin: -2px auto 4px;
  border: 0;
  background: transparent;
  cursor: pointer;
  touch-action: none;
}

.sheet-handle::before {
  content: "";
  display: block;
  width: 42px;
  height: 5px;
  margin: 8px auto;
  border-radius: 99px;
  background: #c6d2cc;
}

.alert-banner {
  margin: 0 0 10px;
  padding: 10px 11px;
  border-radius: 8px;
  background: #fff1ea;
  color: #7d2f16;
  font-size: 13px;
  font-weight: 700;
  line-height: 1.35;
}

.sheet-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
}

.bottom-sheet:not(.is-expanded) .alert-banner,
.bottom-sheet:not(.is-expanded) .eta-list,
.bottom-sheet:not(.is-expanded) .nearby-block {
  display: none;
}

.bottom-sheet:not(.is-expanded) h1 {
  display: -webkit-box;
  overflow: hidden;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 2;
}

.sheet-title-block {
  min-width: 0;
}

.eyebrow,
.section-label {
  color: var(--brand);
  font-size: 11px;
  font-weight: 900;
  letter-spacing: 0;
  text-transform: uppercase;
}

h1 {
  margin: 2px 0 4px;
  font-size: 22px;
  line-height: 1.08;
  letter-spacing: 0;
}

.selected-stop-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  color: var(--muted);
  font-size: 13px;
}

.inline-route {
  display: inline-flex;
  align-items: center;
  gap: 5px;
}

.inline-route::before {
  content: "";
  width: 8px;
  height: 8px;
  border-radius: 99px;
  background: var(--route-color);
}

.eta-list {
  display: grid;
  gap: 8px;
  margin-top: 13px;
}

.eta-card {
  min-height: 64px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel-solid);
}

.eta-route {
  min-width: 0;
  display: flex;
  align-items: center;
  gap: 10px;
}

.eta-route div {
  min-width: 0;
}

.eta-route p {
  overflow: hidden;
  color: var(--ink);
  font-size: 15px;
  font-weight: 800;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.eta-route span,
.eta-time span {
  display: block;
  margin-top: 2px;
  color: var(--muted);
  font-size: 12px;
}

.eta-time {
  flex: 0 0 auto;
  text-align: right;
}

.eta-time strong {
  display: block;
  color: var(--brand-strong);
  font-size: 23px;
  line-height: 1;
}

.nearby-block {
  margin-top: 13px;
}

.nearby-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 8px;
}

.last-updated {
  color: var(--muted);
  font-size: 12px;
  white-space: nowrap;
}

.nearby-stops {
  display: grid;
  gap: 7px;
}

.nearby-stop {
  min-height: 45px;
  display: grid;
  grid-template-columns: auto minmax(0, 1fr) auto;
  align-items: center;
  gap: 9px;
  padding: 8px 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #f9fbfa;
  cursor: pointer;
  text-align: left;
}

.nearby-stop.is-selected {
  border-color: rgba(15, 107, 95, 0.4);
  background: #eef8f4;
}

.nearby-name {
  overflow: hidden;
  color: var(--ink);
  font-size: 13px;
  font-weight: 750;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.nearby-distance {
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
}

.empty-message {
  margin: 0;
  padding: 14px;
  border: 1px dashed #c7d3ce;
  border-radius: 8px;
  background: #f9fbfa;
  color: var(--muted);
  font-size: 14px;
}

.toast {
  position: fixed;
  z-index: 50;
  left: 50%;
  bottom: calc(22px + var(--safe-bottom));
  max-width: calc(100vw - 32px);
  transform: translateX(-50%);
  padding: 10px 13px;
  border-radius: 8px;
  background: rgba(19, 31, 27, 0.92);
  color: #ffffff;
  font-size: 13px;
  box-shadow: 0 12px 28px rgba(15, 25, 22, 0.22);
}

.vehicle-marker {
  background: transparent;
  border: 0;
}

.vehicle-shell {
  width: 38px;
  height: 38px;
  display: grid;
  place-items: center;
  border-radius: 99px;
  background: #ffffff;
  box-shadow: 0 6px 18px rgba(19, 35, 30, 0.25);
}

.vehicle-marker.is-stale .vehicle-shell {
  opacity: 0.58;
  filter: grayscale(0.3);
  box-shadow: 0 4px 12px rgba(19, 35, 30, 0.16);
}

.vehicle-shell svg {
  width: 25px;
  height: 25px;
  fill: var(--vehicle-color);
  stroke: #ffffff;
  stroke-width: 1.1;
  stroke-linejoin: round;
}

.leaflet-control-zoom {
  display: none;
}

.leaflet-control-zoom a {
  color: var(--ink) !important;
}

.leaflet-control-attribution {
  margin-bottom: calc(var(--sheet-collapsed-height) + 4px) !important;
  font-size: 10px;
}

.skeleton-line {
  height: 16px;
  width: 72%;
  border-radius: 99px;
  background: linear-gradient(90deg, #e8efeb 0%, #f6faf8 45%, #e8efeb 90%);
  background-size: 220% 100%;
  animation: shimmer 1.1s linear infinite;
}

.skeleton-line.wide {
  width: 96%;
}

.skeleton-line.short {
  width: 45%;
}

@keyframes shimmer {
  to {
    background-position: -220% 0;
  }
}

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

@media (min-width: 720px) {
  .top-bar,
  .route-filters {
    left: 50%;
    right: auto;
    width: min(520px, calc(100vw - 24px));
    transform: translateX(-50%);
  }

  .bottom-sheet {
    left: 50%;
    right: auto;
    width: min(520px, calc(100vw - 24px));
    margin-bottom: 14px;
    border-radius: 18px;
    background: var(--panel);
    backdrop-filter: blur(16px);
    transform: translateX(-50%) translateY(var(--sheet-drag-offset));
  }

  .bottom-sheet.is-expanded {
    height: min(760px, calc(100dvh - 28px - var(--safe-top)));
    max-height: min(760px, calc(100dvh - 28px - var(--safe-top)));
  }

}

@media (max-width: 390px) {
  .system-button {
    font-size: 14px;
  }

  .status-text {
    font-size: 11px;
  }

  h1 {
    font-size: 20px;
  }

  .route-filter {
    height: 36px;
    padding: 0 9px;
    font-size: 13px;
  }
}
