/* app.css — layout e componentes do Rastreador (mobile-first). */

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { height: 100%; margin: 0; }
body {
  font-family: 'Hanken Grotesk', system-ui, sans-serif;
  color: var(--ink); background: var(--map);
  overscroll-behavior: none;
}

#map { position: fixed; inset: 0; z-index: 0; background: var(--map); }

/* Leaflet: fundo neutro coerente com o tema */
.leaflet-container { background: var(--map); font: inherit; }
/* Modo escuro do mapa via filtro (mantém os tiles OSM, sem outro provedor) */
:root[data-theme="dark"] .leaflet-tile-pane { filter: invert(1) hue-rotate(180deg) brightness(.92) contrast(.95) saturate(.6); }

/* Barra de busca */
.searchbar {
  position: fixed; top: max(14px, env(safe-area-inset-top)); left: 14px; right: 14px; height: 52px;
  display: flex; align-items: center; gap: 10px; padding: 0 16px; z-index: 500;
  background: var(--field); border: 1px solid var(--fieldB); border-radius: 14px; box-shadow: var(--fieldShadow);
}
.searchbar svg { width: 18px; height: 18px; color: var(--bicon); flex: none; }
.searchbar input {
  flex: 1; border: none; background: transparent; outline: none;
  color: var(--ink); font-size: 15px; font-family: inherit;
}
.searchbar input::placeholder { color: var(--muted); }

/* Botão de tema (dev) */
.theme-btn {
  position: fixed; top: max(76px, calc(env(safe-area-inset-top) + 62px)); right: 14px; z-index: 500;
  width: 40px; height: 40px; border-radius: 12px; border: 1px solid var(--fieldB);
  background: var(--surface); color: var(--ink); font-size: 18px; cursor: pointer; box-shadow: var(--fieldShadow);
}

/* FAB recentralizar */
.fab {
  position: fixed; right: 16px; bottom: 96px; z-index: 500;
  width: 48px; height: 48px; border-radius: 14px; border: none; cursor: pointer;
  background: var(--brand); color: var(--brandTxt); box-shadow: var(--fabShadow);
  display: grid; place-items: center;
}
.fab svg { width: 22px; height: 22px; }

/* Bottom-nav */
.bottomnav {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 500; height: 66px;
  padding-bottom: env(safe-area-inset-bottom);
  display: flex; background: var(--navBg);
}
.nav-item {
  flex: 1; border: none; background: transparent; cursor: pointer;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 3px;
  color: var(--navMute); font-size: 11px; font-weight: 600;
}
.nav-item .nav-ico { font-size: 18px; filter: grayscale(.2); }
.nav-item.active { color: var(--navAct); }
.nav-item.dim { color: var(--navDim); opacity: .6; }

/* Marcadores */
.stop-dot {
  width: 13px; height: 13px; background: var(--mkBg); border: 2px solid var(--mkB);
  border-radius: 50% 50% 50% 2px; transform: rotate(45deg);
}
.user-dot {
  width: 18px; height: 18px; border-radius: 50%; background: var(--loc);
  box-shadow: 0 0 0 6px color-mix(in srgb, var(--loc) 22%, transparent), 0 0 0 2px #fff inset;
}

/* Bottom sheet — arrastável: a altura é definida em JS (pontos de ancoragem). */
.sheet {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 600;
  height: 62vh; /* fallback; o JS sobrescreve com a âncora atual */
  display: flex; flex-direction: column;
  background: var(--surface); border-radius: 26px 26px 0 0; border-top: 1px solid var(--hair);
  box-shadow: var(--sheetShadow); padding: 0 20px calc(78px + env(safe-area-inset-bottom));
  transform: translateY(100%);
  transition: transform .3s cubic-bezier(.25,.46,.45,.94), height .28s cubic-bezier(.25,.46,.45,.94);
  overflow: hidden; /* o scroll acontece dentro de .sheet-body */
}
.sheet.open { transform: translateY(0); }
/* Enquanto o dedo/mouse arrasta, a altura segue o gesto sem transição (sem lag). */
.sheet.dragging { transition: transform .3s cubic-bezier(.25,.46,.45,.94); }
.sheet-handle {
  width: 40px; height: 4px; border-radius: 99px; background: var(--handle); margin: 12px auto 14px;
  flex: none; cursor: grab; touch-action: none; /* área de pega maior para o gesto */
  position: relative;
}
.sheet-handle::before { content: ''; position: absolute; left: 50%; top: 50%; transform: translate(-50%, -50%); width: 120px; height: 28px; }
.sheet.dragging .sheet-handle { cursor: grabbing; }
.sheet-head { flex: none; display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; }
.sheet-label { font-size: 11px; letter-spacing: .08em; text-transform: uppercase; font-weight: 700; color: var(--label); }
.sheet-title { font-family: 'Newsreader', serif; font-size: 22px; font-weight: 600; color: var(--ink); margin-top: 2px; }
.sheet-close {
  width: 30px; height: 30px; border-radius: 50%; border: none; cursor: pointer; font-size: 15px;
  background: color-mix(in srgb, var(--ink) 7%, transparent); color: var(--muted);
}
/* Conteúdo rola dentro do sheet quando expandido. Barra de rolagem invisível (mobile). */
.sheet-body { flex: 1; min-height: 0; overflow-y: auto; padding-top: 6px; -webkit-overflow-scrolling: touch; scrollbar-width: none; }
.sheet-body::-webkit-scrollbar { width: 0; height: 0; display: none; }

/* Cabeçalho do sheet: voltar (‹) + título + toggle de sentido + fechar (✕). */
.sheet-back {
  flex: none; width: 32px; height: 32px; margin: -2px 6px 0 -6px; padding: 0; border: none; cursor: pointer;
  background: transparent; color: var(--ink); font-size: 26px; line-height: 1; display: grid; place-items: center;
}
.sheet-back[hidden] { display: none; }
.sheet-head-main { flex: 1; min-width: 0; }
.sheet-toggle { display: flex; gap: 6px; margin-top: 10px; }
.sheet-toggle:empty { display: none; }
.seg {
  flex: 1; min-width: 0; padding: 8px 10px; border-radius: 9px; cursor: pointer; font-family: inherit;
  border: 1px solid var(--chipB); background: transparent; color: var(--muted);
  font-size: 12px; font-weight: 700; text-align: center; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.seg.ativo { background: var(--brand); color: var(--brandTxt); border-color: var(--brand); }

/* No estado "peek" (recolhido), o painel mostra só o cabeçalho. */
.sheet.peek .sheet-toggle, .sheet.peek .sheet-body { opacity: 0; pointer-events: none; }
.line-card.clicavel { cursor: pointer; }

/* Card de linha */
.line-card { display: flex; align-items: center; gap: 12px; padding: 14px 2px; border-bottom: 1px solid var(--hair); }
.badge {
  flex: none; font-weight: 800; font-size: 13px; color: var(--brandTxt); background: var(--brand);
  border-radius: 6px; padding: 6px 8px;
}
.badge.outline { background: transparent; color: var(--chipTxt); border: 1.5px solid var(--chipB); }
.line-info { flex: 1; min-width: 0; }
.line-dest { font-family: 'Newsreader', serif; font-size: 16.5px; font-weight: 600; color: var(--ink); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.line-sub { font-size: 11.5px; color: var(--muted); margin-top: 2px; }

/* Pílula de ETA — o semáforo */
.eta-pill {
  flex: none; display: inline-flex; align-items: center; gap: 5px; padding: 6px 10px; border-radius: 11px;
  color: var(--status, var(--ok));
  background: color-mix(in srgb, var(--status, var(--ok)) 13%, transparent);
  border: 1px solid color-mix(in srgb, var(--status, var(--ok)) 26%, transparent);
}
.eta-pill svg { width: 14px; height: 14px; }
.eta-pill .num { font-weight: 800; font-size: 22px; line-height: 1; font-variant-numeric: tabular-nums; }
.eta-pill .min { font-weight: 700; font-size: 11px; }
.s-pontual { --status: var(--ok); }
.s-razoavel { --status: var(--warn); }
.s-pode_atrasar, .s-desviou { --status: var(--bad); }
.s-sem_live { --status: var(--idle); }

/* Avisos / estados */
.demo-note {
  margin: 8px 0 2px; padding: 8px 12px; border-radius: 10px; font-size: 12px; color: var(--muted);
  background: color-mix(in srgb, var(--idle) 12%, transparent); border: 1px dashed var(--chipB);
}
.state { text-align: center; padding: 26px 10px; color: var(--muted); }
.state .state-title { font-family: 'Newsreader', serif; font-size: 19px; color: var(--ink); margin-bottom: 6px; }
.state button {
  margin-top: 14px; padding: 12px 20px; border: none; border-radius: 12px; cursor: pointer;
  background: var(--brand); color: var(--brandTxt); font-weight: 700; font-family: inherit;
}
.muted { color: var(--muted); }

/* Marcador de veículo */
.bus-marker {
  display: grid; place-items: center; width: 26px; height: 22px; border-radius: 8px;
  background: var(--brand); border: 2px solid var(--surface); box-shadow: 0 3px 8px rgba(0,0,0,.25);
}
.bus-marker svg { width: 12px; height: 12px; fill: var(--brandTxt); }
.bus-marker.hi { background: var(--ok); border-radius: 9px; box-shadow: var(--haloOk); }

/* Overlay de busca (Fluxo B) */
.overlay {
  position: fixed; inset: 0; z-index: 700; background: var(--surface);
  display: flex; flex-direction: column; padding: max(14px, env(safe-area-inset-top)) 14px 0;
}
.overlay[hidden] { display: none; }
.overlay .search-row { display: flex; align-items: center; gap: 10px; }
.overlay .back { width: 40px; height: 40px; flex: none; border: none; background: transparent; color: var(--ink); font-size: 22px; cursor: pointer; }
.overlay .field {
  flex: 1; display: flex; align-items: center; gap: 10px; height: 52px; padding: 0 16px;
  background: var(--field); border: 1.5px solid var(--brand); border-radius: 14px;
}
.overlay .field svg { width: 18px; height: 18px; color: var(--bicon); }
.overlay .field input { flex: 1; border: none; background: transparent; outline: none; color: var(--ink); font-size: 15px; font-family: inherit; }
.results { margin-top: 14px; overflow-y: auto; }
.results .results-label { font-size: 11px; letter-spacing: .06em; text-transform: uppercase; color: var(--muted); font-weight: 700; margin: 6px 2px 8px; }

/* Resultado de linha (com os dois sentidos) */
.line-result { padding: 12px 2px; border-bottom: 1px solid var(--hair); }
.line-result.busca-item { cursor: pointer; }
.line-card.semlive { opacity: .68; }
.line-result .head { display: flex; align-items: center; gap: 10px; }
.line-result .title { font-family: 'Newsreader', serif; font-size: 16px; font-weight: 600; color: var(--ink); }
.sense-chips { display: flex; gap: 8px; margin-top: 10px; }
.sense-chip {
  flex: 1; display: flex; align-items: center; gap: 7px; padding: 8px 10px; cursor: pointer;
  border: 1px solid var(--chipB); border-radius: 10px; background: transparent; text-align: left; color: var(--ink); font-family: inherit;
}
.sense-chip .tag { font-size: 10px; font-weight: 700; color: var(--label); background: color-mix(in srgb, var(--brand) 12%, transparent); border-radius: 5px; padding: 2px 6px; }
.sense-chip .dest { font-size: 12.5px; color: var(--ink); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* Linha de veículo (tela 6) */
.veh-row { display: flex; align-items: center; gap: 12px; padding: 14px 2px; border-bottom: 1px solid var(--hair); }
.veh-avatar { width: 38px; height: 38px; flex: none; border-radius: 50%; display: grid; place-items: center; background: color-mix(in srgb, var(--status, var(--ok)) 13%, transparent); color: var(--status, var(--ok)); }
.veh-avatar svg { width: 18px; height: 18px; fill: currentColor; }
.veh-info { flex: 1; min-width: 0; }
.veh-title { font-family: 'Newsreader', serif; font-size: 16px; font-weight: 600; color: var(--ink); }
.veh-sub { font-size: 11.5px; color: var(--muted); margin-top: 2px; }

/* Lista de pontos do trajeto (tela 5) */
.stop-item { cursor: pointer; }
.stop-bullet { width: 11px; height: 11px; flex: none; border-radius: 50%; background: var(--chipB); }
.stop-bullet.near { width: 13px; height: 13px; background: transparent; border: 3px solid var(--ok); box-sizing: border-box; }
.chev { color: var(--muted); font-size: 18px; flex: none; }

/* Banner (ex.: localização negada) */
.banner {
  position: fixed; left: 14px; right: 14px; bottom: 156px; z-index: 550;
  background: var(--surface); border: 1px solid var(--hair); border-radius: 12px;
  padding: 11px 14px; font-size: 13px; color: var(--ink); box-shadow: var(--fabShadow);
}
.banner[hidden] { display: none; }
.banner button { background: none; border: none; color: var(--brand); font-weight: 700; cursor: pointer; text-decoration: underline; font-family: inherit; font-size: 13px; padding: 0; }

/* Skeleton de carregamento */
.sk { border-radius: 7px; background: color-mix(in srgb, var(--ink) 9%, transparent); animation: pulse 1.4s ease-in-out infinite; }
.sk-row { display: flex; align-items: center; gap: 12px; padding: 14px 2px; }
@keyframes pulse { 0%,100% { opacity: .55; } 50% { opacity: .9; } }

