/* Celular primeiro: lista e mapa em telas separadas, topo baixo, placar que rola para o lado, filtros recolhidos,
   detalhe como folha que sobe de baixo e alvos de toque de 40 px ou mais. Também alivia o desenho: sem desfoque
   (backdrop-filter) sobre o mapa e cards fora da tela não são desenhados. */

/* ---------- valem em qualquer tela ---------- */
.cel-nav, .cel-veu, .cel-bt-filtros, .det-vermapa { display: none; }
.filtros-mais { display: contents; }
/* cards fora da área visível ficam sem desenhar (o navegador reserva a altura e desenha quando chegam perto) */
.ev { content-visibility: auto; contain-intrinsic-size: auto 84px; }
.feed-mais {
  display: block; width: calc(100% - 24px); margin: 12px; height: 42px; border: 1px dashed var(--linha-2); border-radius: var(--raio);
  font: 700 13px var(--t); color: var(--tinta-2); background: var(--fundo);
}
.feed-mais:hover { color: var(--tinta); border-color: var(--tinta-3); }

@media (max-width: 820px) {
  :root { --cel-nav: calc(58px + env(safe-area-inset-bottom)); --tl-alt: 60px; }
  html, body { height: 100%; }
  body { height: 100dvh; overflow: hidden; }

  /* ---------- topo: logo, nome e ícones numa linha ---------- */
  .barra { height: calc(48px + env(safe-area-inset-top)); padding: env(safe-area-inset-top) 4px 2px 12px; flex-wrap: nowrap; gap: 8px; }
  .marca { flex: 1; min-width: 0; gap: 8px; }
  .logos { flex-shrink: 0; padding-right: 8px; gap: 0; }
  .logos img { height: 18px; }
  .logos img + img { display: none; }
  .marca-titulo { min-width: 0; display: block; }
  .marca { overflow: hidden; }
  .marca h1 { font-size: 11.5px; line-height: 1.05; letter-spacing: .04em; white-space: normal; }
  .marca-ufs { display: none; }
  .acoes-topo { width: auto; flex-shrink: 0; gap: 0; margin-left: auto; }
  .acoes-topo .bt:not(.bt-icone) { flex: none; }
  .barra .bt, .barra .bt-icone { width: 40px; height: 40px; padding: 0; justify-content: center; }
  .barra .bt span, .barra .bt b { display: none; }
  .barra .bt .ph { font-size: 20px; }
  .barra .bt-sinal { background: transparent; border-color: transparent; color: var(--sinal); }

  /* ---------- placar: chips numa linha que rola para o lado, com o nome de cada número ---------- */
  .resumo { padding: 6px 0; gap: 0; }
  .placar { width: 100%; display: flex; gap: 6px; padding: 0 12px; overflow-x: auto; scroll-snap-type: x proximity; scrollbar-width: none; overscroll-behavior-x: contain; }
  .placar::-webkit-scrollbar { display: none; }
  .placar button { flex: none; height: 36px; padding: 0 12px 0 10px; border: 1px solid var(--linha); border-radius: 18px; scroll-snap-align: start; animation: none !important; }
  .placar span { display: inline; font-size: 12px; }
  .placar b, .placar .destaque b, .placar .neutro b { font-size: 17px; }
  .placar .destaque { grid-column: auto; }

  /* ---------- área principal: lista OU mapa, cada um na tela inteira ---------- */
  .area { position: relative; display: block; flex: 1; min-height: 0; border-top: 0; }
  .livro, .mapa-area { position: absolute; left: 0; right: 0; top: 0; }
  .livro { bottom: 0; z-index: 2; border-right: 0; padding-bottom: var(--cel-nav); }
  .mapa-area { order: 0; height: auto; bottom: var(--cel-nav); isolation: isolate; }
  body:not([data-vista="mapa"]) .mapa-area { visibility: hidden; }
  body[data-vista="mapa"] .livro { visibility: hidden; }
  .feed { overflow-y: auto; overscroll-behavior: contain; scroll-behavior: auto; }

  /* ---------- barra de baixo: Lista | Mapa ---------- */
  .cel-nav {
    display: flex; position: fixed; left: 0; right: 0; bottom: 0; z-index: 900; height: var(--cel-nav); padding-bottom: env(safe-area-inset-bottom);
    background: var(--painel); border-top: 1px solid var(--linha-2); box-shadow: 0 -4px 16px rgba(0,0,0,.14);
  }
  .cel-nav button { position: relative; flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 3px; font: 700 12px var(--t); color: var(--tinta-3); -webkit-tap-highlight-color: transparent; }
  .cel-nav .ph { font-size: 24px; }
  .cel-nav button[aria-pressed="true"] { color: var(--tinta); }
  .cel-nav button[aria-pressed="true"]::before { content: ''; position: absolute; top: 0; left: 32%; right: 32%; height: 3px; border-radius: 0 0 3px 3px; background: var(--sinal); }
  .cel-nav em { position: absolute; top: 5px; left: calc(50% + 9px); min-width: 18px; height: 17px; padding: 0 5px; border-radius: 9px; font: 700 11px/17px var(--m); font-style: normal; text-align: center; background: var(--painel-2); color: var(--tinta-2); }
  .cel-nav em:empty { display: none; }
  .cel-nav [data-cel="mapa"] em { background: var(--vermelho); color: #fff; }

  /* ---------- busca + filtros recolhidos ---------- */
  /* minmax(0, …) e min-width: 0: as linhas de botões rolam dentro delas; sem isso esticavam a página inteira */
  .filtros { grid-template-columns: minmax(0, 1fr) auto; padding: 8px 12px; gap: 8px; }
  .filtros-mais, .filtro-linha, .segmento { min-width: 0; max-width: 100%; }
  .busca { height: 42px; }
  .busca input { font-size: 16px; } /* 16 px: o iPhone não dá zoom ao tocar */
  .cel-bt-filtros {
    display: inline-flex; align-items: center; gap: 6px; height: 42px; padding: 0 12px; border: 1px solid var(--linha-2); border-radius: var(--raio);
    background: var(--fundo); font: 700 13px var(--t); color: var(--tinta);
  }
  .cel-bt-filtros .ph { font-size: 18px; }
  .cel-bt-filtros b { min-width: 18px; height: 18px; padding: 0 5px; display: grid; place-items: center; border-radius: 9px; background: var(--sinal); color: var(--sinal-tinta); font: 800 11px var(--m); }
  .cel-bt-filtros[aria-expanded="true"] { border-color: var(--sinal); box-shadow: 0 0 0 3px color-mix(in srgb, var(--sinal) 20%, transparent); }
  .filtros-mais { display: none; grid-column: 1 / -1; gap: 10px; }
  .cel-filtros .filtros-mais { display: grid; }
  .filtro-linha { gap: 8px; }
  .segmento { width: 100%; overflow-x: auto; scrollbar-width: none; }
  .segmento::-webkit-scrollbar { display: none; }
  .segmento button { flex: 1 0 auto; height: 40px; padding: 0 12px; }
  .segmento button span { display: inline; }
  .segmento .uf-lista { height: 40px; }
  .opcoes { flex-wrap: wrap; gap: 2px 14px; }
  .opcoes label { white-space: nowrap; }
  .opcoes label { min-height: 40px; font-size: 14px; margin-right: 0; }
  .opcoes input { width: 18px; height: 18px; }
  .link-prio { min-height: 40px; }

  /* ---------- abas e grupos ---------- */
  /* abas: sem ícone; com as 4 do administrador, se não couber, a linha rola para o lado (sem esticar a página) */
  .abas { overflow-x: auto; scrollbar-width: none; }
  .abas::-webkit-scrollbar { display: none; }
  .abas button { flex: 1 0 auto; padding: 0 10px; height: 44px; font-size: 13px; gap: 5px; }
  .abas button i { display: none; }
  .grupo { backdrop-filter: none; background: var(--painel); }
  .revendo { flex-wrap: wrap; font-size: 12.5px; }

  /* ---------- cards: escudo à esquerda com a hora embaixo, título com até 3 linhas ---------- */
  .ev { grid-template-columns: 46px 1fr auto; grid-template-areas: "via corpo estado" "hora corpo estado"; gap: 2px 10px; padding: 12px 12px 12px 14px; contain-intrinsic-size: auto 96px; transition: none; }
  .ev:hover { transform: none; }
  .ev-via { grid-area: via; min-width: 0; }
  .ev-hora { grid-area: hora; text-align: center; font-size: 11.5px; padding-top: 3px; }
  .ev-hora small { font-size: 10.5px; margin-top: 1px; }
  .ev-corpo { grid-area: corpo; }
  .ev-estado { grid-area: estado; }
  .ev-titulo { font-size: 15.5px; line-height: 1.22; -webkit-line-clamp: 3; }
  .ev-meta { font-size: 12.5px; gap: 2px 10px; }
  /* Procede / Não procede: no celular ficam no detalhe (no card dobravam a altura); a etiqueta já respondida continua */
  .ev-av.so-admin, .ev-av button { display: none; }
  .feed-mais { height: 48px; }

  /* ---------- detalhe: folha que sobe de baixo (arrastar o topo para baixo fecha) ---------- */
  .detalhe {
    position: fixed; left: 0; right: 0; bottom: 0; top: auto; z-index: 950; width: 100%; max-height: 88dvh;
    border: 0; border-radius: 16px 16px 0 0; box-shadow: 0 -12px 40px rgba(0,0,0,.4); padding-bottom: env(safe-area-inset-bottom);
    transition: transform .25s var(--ease);
  }
  .detalhe:not([hidden]) { animation: folha .3s var(--ease); }
  @keyframes folha { from { transform: translateY(35%); opacity: .5; } }
  .det-topo { position: relative; padding: 18px 10px 10px 14px; touch-action: none; }
  .det-topo::before { content: ''; position: absolute; top: 6px; left: 50%; width: 40px; height: 4px; margin-left: -20px; border-radius: 2px; background: color-mix(in srgb, var(--tinta-3) 60%, transparent); }
  .det-topo .fechar { width: 40px; height: 40px; }
  .det-topo .fechar .ph { font-size: 20px; }
  .det-corpo { flex: 1 1 auto; min-height: 0; overscroll-behavior: contain; }
  .det-corpo h2 { font-size: 20px; }
  .det-dados { font-size: 13.5px; }
  .det-fontes a { padding: 4px 0; }
  .det-vermapa {
    display: flex; align-items: center; justify-content: center; gap: 8px; margin: 10px 14px 0; height: 44px; border-radius: var(--raio);
    font: 700 14px var(--t); color: var(--tinta); border: 1px solid var(--linha-2); background: var(--painel-2);
  }
  .det-vermapa .ph { font-size: 18px; color: var(--sinal-texto); }
  .det-navegar { height: 44px; margin-top: 8px; font-size: 14px; }
  .det-acoes .bt, .det-manual .bt, .det-av .bt { height: 44px; }
  .det-erro { min-height: 44px; }
  .det-av { padding: 12px 14px; margin-top: 0; }
  .cel-veu { display: block; position: fixed; inset: 0; z-index: 940; background: rgba(5, 10, 12, .5); opacity: 0; pointer-events: none; transition: opacity .2s; }
  body:has(#detalhe:not([hidden])) .cel-veu { opacity: 1; pointer-events: auto; }

  /* ---------- mapa: menos botões (pinça faz o zoom), alvos maiores, sem desfoque ---------- */
  .m3-ctl { top: 10px; right: 10px; backdrop-filter: none; background: var(--painel); }
  .m3-ctl [data-ctl="mais"], .m3-ctl [data-ctl="menos"], .m3-ctl [data-ctl="tela"], .m3-ctl [data-ctl="tour"] { display: none; }
  .m3-ctl button { width: 44px; height: 44px; font-size: 19px; }
  .m3-rodovias { top: 10px; left: 10px; width: min(280px, calc(100% - 76px)); max-height: calc(100% - var(--tl-alt) - 40px); backdrop-filter: none; background: var(--painel); }
  .m3-rodovias:not(.recolhido) .m3-rod-lista { max-height: none; }
  .m3-rodovias header { min-height: 44px; }
  .m3-rodovias header button { width: 40px; height: 40px; }
  .maplibregl-popup.m3-pop { display: none; } /* dica de "passar o mouse": no toque, o detalhe abre direto */
  .marca-agua { display: none; }
  .maplibregl-ctrl-bottom-right { right: 6px; bottom: calc(var(--tl-alt) + 14px); }

  /* linha do tempo compacta: relógio, play, trilho e "Ao vivo" (sem as marcas de hora, que se encavalavam) */
  .tl { left: 8px; right: 8px; bottom: 8px; height: var(--tl-alt); grid-template-columns: auto auto 1fr auto; gap: 8px; padding: 6px 8px; backdrop-filter: none; background: var(--painel); }
  .tl-relogio { min-width: 0; }
  .tl-relogio small { font-size: 9px; letter-spacing: .12em; }
  .tl-relogio b { font-size: 22px; }
  .tl-relogio span, .tl-relogio.noite b::after { display: none; }
  .tl-play { width: 40px; height: 40px; font-size: 18px; }
  .tl-marcas { display: none; }
  .tl-trilho canvas { top: 4px; bottom: 4px; height: calc(100% - 8px); }
  .tl-trilho input[type=range] { inset: 0; height: 100%; }
  .tl-vivo { height: 36px; padding: 0 10px; font-size: 12px; }

  /* ---------- janelas (fontes, trechos, cadastro): sobem de baixo, ocupando a largura ---------- */
  dialog { width: 100%; max-width: 100%; max-height: 92dvh; margin: auto 0 0; border: 0; border-radius: 16px 16px 0 0; }
  dialog .x { width: 40px; height: 40px; }
  .dlg-manual, .dlg-manual form { max-height: 94dvh; }

  .aviso { z-index: 960; bottom: calc(var(--cel-nav) + 12px); max-width: calc(100% - 24px); }
}

/* administrador tem 6 botões no topo: em tela de celular o logo cede o lugar ao nome */
@media (max-width: 480px) {
  [data-perfil="admin"] .barra .logos { display: none; }
}
/* administrador no celular: 8 botões no topo (com Paz News e Ajuda); um pouco mais estreitos para o nome caber */
@media (max-width: 440px) {
  [data-perfil="admin"] .barra .bt, [data-perfil="admin"] .barra .bt-icone { width: 34px; }
  [data-perfil="admin"] .barra .bt .ph { font-size: 19px; }
}
/* telas bem estreitas (celular pequeno) */
@media (max-width: 380px) {
  .marca h1 { font-size: 12px; letter-spacing: .02em; }
  .barra .bt, .barra .bt-icone { width: 36px; }
}
