:root {
  --green: #0B8A5F;
  --live: #00A86B;
  --me: #1E88E5;
  --ink: #111827;
  --muted: #6B7280;
  --line: #F1F5F9;
  --card: #FFFFFF;
  --soft: #F3F4F6;
  --shadow: 0 4px 18px rgba(0, 0, 0, 0.16);
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  color-scheme: light;
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; overflow: hidden; }
body {
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  color: var(--ink);
  background: #E8EEEB;
  -webkit-tap-highlight-color: transparent;
  overscroll-behavior: none;
}
button { font: inherit; color: inherit; background: none; border: 0; padding: 0; cursor: pointer; text-align: left; }
button:disabled { opacity: 0.45; cursor: default; }
h2 { margin: 12px 0 4px; font-size: 1.3rem; }
h3 { margin: 16px 0 8px; font-size: 1rem; }
hr { border: 0; border-top: 1px solid #E5E7EB; margin: 8px 0; }
small { font-size: 12px; }

.ic { width: 20px; height: 20px; fill: currentColor; flex: none; }
.muted { color: var(--muted); }
.center { text-align: center; }
.small { font-size: 13px; }
.tiny { font-size: 11px; margin: 12px 0; }
.strong { font-weight: 600; }
.pre { white-space: pre-line; }
.err { color: #C62828; }
.c-live { color: var(--live); fill: var(--live); }
.c-me { color: var(--me); fill: var(--me); }
.c-origin { fill: #2E7D32; }
.c-dest { fill: #C62828; }
.c-live .ic, .c-me .ic, p.c-live .ic, p.muted .ic { width: 16px; height: 16px; vertical-align: -3px; }
.grow { flex: 1; min-width: 0; }
.row { display: flex; align-items: center; }
.row.gap { gap: 8px; flex-wrap: wrap; }
.head { gap: 10px; padding-top: 10px; padding-bottom: 6px; }
.pad { padding: 16px; }
.pad-x { padding-left: 16px; padding-right: 16px; }
.ellipsis { display: block; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.clamp2 { display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; font-size: 14px; }

#map { position: fixed; inset: 0; }

/* ---------- topo ---------- */
#top {
  position: fixed; z-index: 3;
  top: calc(12px + var(--safe-top)); left: 12px; right: 12px;
  display: flex; flex-direction: column; gap: 8px;
  pointer-events: none;
}
#top > * { pointer-events: auto; }
.card { background: var(--card); border-radius: 16px; box-shadow: var(--shadow); }
.trip { display: flex; align-items: center; padding: 4px 4px 4px 16px; }
.endpoints { flex: 1; min-width: 0; }
.endpoints hr { margin: 0 0 0 36px; border-color: #E5E7EB; }
.endpoint { display: flex; align-items: center; gap: 16px; width: 100%; padding: 12px 0; font-weight: 500; }
.endpoint span { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.endpoint .ph { color: var(--muted); font-weight: 400; }
.icon-btn { width: 44px; height: 44px; display: grid; place-items: center; border-radius: 50%; flex: none; }
.icon-btn:hover { background: var(--soft); }
.titlebar { display: flex; align-items: center; gap: 4px; padding: 4px; font-size: 1.05rem; }

.chips { display: flex; gap: 6px; overflow-x: auto; scrollbar-width: none; padding: 2px; }
.chips::-webkit-scrollbar { display: none; }
.chips.inline { margin: 4px 0 8px; }
.chip {
  flex: none; position: relative; padding: 7px 14px; border-radius: 9px;
  background: var(--card); border: 1px solid #D1D5DB; font-size: 14px; font-weight: 500;
  box-shadow: 0 1px 3px rgba(0,0,0,.08);
}
.chip.on { background: #DCEFE7; border-color: #9FD3BD; color: #065F46; }
.chip input[type="time"] { position: absolute; inset: 0; opacity: 0; width: 100%; cursor: pointer; }

.banner {
  display: flex; align-items: center; gap: 8px; padding: 4px 4px 4px 14px;
  background: #263238; color: #fff; border-radius: 12px; font-size: 14px;
}
.banner span { flex: 1; padding: 8px 0; }
.banner .icon-btn:hover { background: rgba(255,255,255,.12); }

/* ---------- painel ---------- */
#panel {
  position: fixed; z-index: 2; left: 0; right: 0; bottom: 0;
  max-height: 46vh; max-height: 46dvh;
  display: flex; flex-direction: column;
  background: var(--card); border-radius: 20px 20px 0 0;
  box-shadow: 0 -4px 22px rgba(0, 0, 0, 0.14);
  padding-bottom: var(--safe-bottom);
}
.grip { width: 36px; height: 4px; border-radius: 4px; background: #D1D5DB; margin: 8px auto 0; flex: none; }
.panel-body { overflow-y: auto; -webkit-overflow-scrolling: touch; overscroll-behavior: contain; }
.panel-body p { margin: 4px 0; }

.live-status { display: flex; align-items: center; gap: 6px; font-size: 13px; color: var(--muted); }
.live-status .ic { width: 16px; height: 16px; }

.btn {
  display: inline-flex; align-items: center; gap: 6px; padding: 10px 16px;
  border: 1px solid #D1D5DB; border-radius: 22px; font-weight: 500; background: var(--card); white-space: nowrap;
}
.btn .ic { width: 18px; height: 18px; }
.btn:hover:not(:disabled) { background: var(--soft); }
.btn.primary { background: var(--green); border-color: var(--green); color: #fff; margin-top: 12px; }
.tip { margin-top: 12px !important; padding: 10px 12px; border-radius: 10px; background: #EEF6F2; font-size: 13px; }
.tip.warn { background: #FFF4E5; }
.link { color: var(--me); font-weight: 600; text-decoration: underline; display: inline; }
.share { display: inline-block; transform: rotate(-90deg); }

.item {
  display: flex; align-items: center; gap: 10px; width: 100%;
  padding: 12px 16px; border-bottom: 1px solid var(--line);
}
.item:hover { background: #FAFBFB; }
.item .right { text-align: right; display: flex; flex-direction: column; align-items: flex-end; min-width: 64px; }
.option { align-items: flex-start; }
.seq { display: flex; flex-wrap: wrap; align-items: center; row-gap: 4px; margin-bottom: 4px; }
.walk { display: inline-flex; align-items: center; font-size: 12px; color: var(--muted); fill: var(--muted); }
.walk .ic { width: 18px; height: 18px; }
.chev { color: var(--muted); padding: 0 6px; }
.times { display: block; color: #374151; margin-top: 2px; }
.big-time { font-size: 18px; }

.badge {
  display: inline-flex; align-items: center; gap: 4px; flex: none;
  padding: 3px 8px; border-radius: 6px; color: #fff; fill: #fff; font-weight: 700; font-size: 14px;
}
.badge .ic { width: 14px; height: 14px; }
.badge.big { padding: 5px 8px; font-size: 16px; }
.badge.big .ic { width: 18px; height: 18px; }

.live { display: flex; flex-direction: column; align-items: flex-end; color: var(--live); fill: var(--live); }
.live span { display: inline-flex; align-items: center; gap: 2px; font-weight: 700; font-size: 18px; }
.live .ic { width: 14px; height: 14px; }

.step { display: flex; align-items: center; gap: 12px; padding: 6px 0; }
.step .ic { width: 22px; height: 22px; }
.step-title { font-size: 14px; font-weight: 500; }

.times-grid { display: flex; flex-wrap: wrap; gap: 6px; }
.times-grid span { padding: 6px 10px; border-radius: 8px; background: #E8F5EF; color: #065F46; font-size: 13px; font-weight: 500; }
.times-grid span.past { background: var(--soft); color: var(--muted); }
.trip-row {
  display: flex; align-items: center; gap: 8px; padding: 8px 10px; margin-bottom: 6px;
  border-radius: 8px; background: #F6F8F7; font-size: 13px;
}
.trip-row .arrive { color: #065F46; }

.spinner {
  width: 28px; height: 28px; margin: 12px auto; border-radius: 50%;
  border: 3px solid #D1FAE5; border-top-color: var(--green); animation: spin .8s linear infinite;
}
.spinner.small { width: 18px; height: 18px; border-width: 2px; margin: 8px 0; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- botão "voltar para mim" ---------- */
.fab {
  position: fixed; z-index: 2; right: 16px; bottom: calc(46dvh + 12px);
  width: 48px; height: 48px; border-radius: 50%; display: grid; place-items: center;
  background: var(--card); box-shadow: var(--shadow); fill: var(--me);
}
.fab .ic { width: 24px; height: 24px; }
.fab[hidden] { display: none; }

/* ---------- busca ---------- */
#search {
  position: fixed; inset: 0; z-index: 5; background: var(--card);
  display: flex; flex-direction: column; padding-top: var(--safe-top);
}
#search[hidden] { display: none; }
.search-bar { display: flex; align-items: center; gap: 4px; padding: 8px; }
#search-input {
  flex: 1; min-width: 0; padding: 12px 14px; border: 0; border-radius: 12px;
  background: var(--soft); font: inherit; font-size: 16px; outline: none;
}
#search-list { overflow-y: auto; flex: 1; padding-bottom: var(--safe-bottom); }
.round { width: 36px; height: 36px; border-radius: 50%; background: var(--soft); display: grid; place-items: center; flex: none; fill: #374151; }
#search-list .item .grow { display: flex; flex-direction: column; }

/* ---------- computador: painéis numa coluna à esquerda ---------- */
@media (min-width: 900px) {
  #top { right: auto; width: 400px; }
  #panel {
    left: 12px; right: auto; bottom: 12px; width: 400px;
    max-height: calc(100vh - 220px); border-radius: 16px;
  }
  .fab { bottom: 24px; right: 24px; }
  #search { inset: 12px auto 12px 12px; width: 400px; border-radius: 16px; box-shadow: var(--shadow); }
}
