* { box-sizing: border-box; }

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

body {
  font-family: system-ui, sans-serif;
  color: #1c1c1c;
}

/* .screen nunca deve ultrapassar a viewport -- nenhum elemento dentro dele
   pode gerar scroll de PAGINA; cada area com muito conteudo (sidebar,
   secao-corpo, resultado-painel) tem seu proprio overflow-y interno. */
.screen { height: 100vh; overflow: hidden; }
.hidden { display: none !important; }

/* Chrome mobile novo (barra inferior de modulos, abas Rota/Mapa/Resultado,
   FAB de calcular, dropdown do cabecalho) -- so' existe/aparece dentro do
   @media (max-width: 768px) no fim deste arquivo. Essas regras aqui em cima
   so' afetam os elementos NOVOS (nao regride nada existente): escondidos por
   padrao, e o wrapper do menu mobile vira "invisivel" no desktop (os filhos
   continuam flex items diretos do <header>, exatamente como antes dele
   existir). */
#menu-hamburguer-btn, #roteirizacao-mobile-tabs, #calcular-btn-fab { display: none; }
#header-menu-mobile { display: contents; }
header { position: relative; }

#login-screen {
  display: flex;
  align-items: center;
  justify-content: center;
  background: #0f3d3e;
}

.login-box {
  background: #fff;
  padding: 32px;
  border-radius: 8px;
  width: 320px;
  text-align: center;
}

.login-box .logo { height: 28px; margin-bottom: 8px; }
.login-box input { width: 100%; padding: 10px; margin: 12px 0; border: 1px solid #ccc; border-radius: 4px; }
.login-box button, #calcular-btn, #logout-btn {
  width: 100%;
  padding: 10px;
  background: #0f3d3e;
  color: #fff;
  border: none;
  border-radius: 4px;
  cursor: pointer;
  font-weight: 600;
  transition: background .15s, transform .05s;
}
.login-box button:hover, #calcular-btn:hover, #logout-btn:hover { background: #145453; }
.login-box button:active, #calcular-btn:active, #logout-btn:active { transform: scale(0.99); }
#logout-btn { width: auto; padding: 8px 16px; background: rgba(255,255,255,0.12); }
#logout-btn:hover { background: rgba(255,255,255,0.22); }
#calcular-btn { font-size: 15px; padding: 12px; box-shadow: 0 2px 6px rgba(15,61,62,0.3); }
.error { color: #b00020; min-height: 20px; }
.login-links { margin-top: 16px; display: flex; flex-direction: column; gap: 6px; }
.login-links a { font-size: 12px; color: #0f3d3e; text-decoration: underline; }

.login-sso { display: flex; flex-direction: column; gap: 8px; margin-bottom: 4px; }
.login-sso-btn {
  display: block;
  width: 100%;
  padding: 10px;
  border: 1px solid #ccc;
  border-radius: 4px;
  color: #1c1c1c;
  text-decoration: none;
  font-weight: 600;
  box-sizing: border-box;
  transition: background .15s;
}
.login-sso-btn:hover { background: #f2f2f2; }
.login-divisor { display: flex; align-items: center; gap: 8px; margin: 14px 0; color: #999; font-size: 12px; }
.login-divisor::before, .login-divisor::after { content: ""; flex: 1; height: 1px; background: #ddd; }

.login-tabs { display: flex; gap: 4px; margin-bottom: 8px; border-bottom: 1px solid #ddd; }
.login-tab {
  flex: 1;
  padding: 8px;
  background: none;
  border: none;
  border-bottom: 2px solid transparent;
  color: #666;
  font-weight: 600;
  cursor: pointer;
}
.login-tab-ativa { color: #0f3d3e; border-bottom-color: #0f3d3e; }
.login-form { display: flex; flex-direction: column; }
#chave-manual-box { margin-top: 12px; }

#app-screen {
  display: flex;
  flex-direction: column;
}

header {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 10px 20px;
  background: linear-gradient(120deg, #0f3d3e 0%, #145453 100%);
  color: #fff;
  box-shadow: 0 1px 6px rgba(0,0,0,0.2);
}
header .logo-header { height: 32px; flex: 0 0 auto; }
#saldo-box { flex: 1; font-size: 13px; }
#saldo-box #saldo-valor { font-weight: 700; color: #ffd166; }
#comprar-creditos-btn {
  margin-left: 10px;
  padding: 3px 10px;
  font-size: 11px;
  background: rgba(255,209,102,0.15);
  color: #ffd166;
  border: 1px solid rgba(255,209,102,0.5);
  border-radius: 12px;
  cursor: pointer;
}
#comprar-creditos-btn:hover { background: rgba(255,209,102,0.28); }
.pacotes-pix { display: flex; flex-direction: column; gap: 8px; margin: 12px 0; }
.pacote-pix-btn {
  display: flex;
  justify-content: space-between;
  padding: 10px 14px;
  border: 1px solid #ddd;
  border-radius: 6px;
  background: #fafafa;
  cursor: pointer;
  font-weight: 600;
  color: #1c1c1c;
}
.pacote-pix-btn:hover { background: #f0f0f0; border-color: #0f3d3e; }
.pix-qrcode { text-align: center; margin: 12px 0; }
.pix-qrcode img { max-width: 220px; }
.pix-copia-cola {
  width: 100%;
  padding: 8px;
  font-size: 11px;
  font-family: monospace;
  border: 1px solid #ccc;
  border-radius: 4px;
  resize: none;
}
.pix-status { text-align: center; font-weight: 600; margin-top: 8px; }
.pix-status-pendente { color: #b8860b; }
.pix-status-creditado { color: #1a7a1a; }
.pix-status-expirado { color: #b00020; }
#usuario-info { font-size: 11px; color: #cfe8e7; margin-bottom: 2px; }
.header-links { display: flex; gap: 16px; }
.header-links a { color: #cfe8e7; font-size: 12px; text-decoration: none; white-space: nowrap; padding: 4px 2px; border-bottom: 2px solid transparent; transition: border-color .15s, color .15s; }
.header-links a:hover { color: #fff; border-bottom-color: #ffd166; }

#app-body { display: flex; flex: 1; min-height: 0; }

#modulos-rail {
  flex: 0 0 auto;
  width: 76px;
  display: flex;
  flex-direction: column;
  align-items: stretch;
  gap: 2px;
  padding: 10px 0;
  background: #0f3d3e;
}

.modulo-icone {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 3px;
  padding: 10px 2px;
  background: none;
  border: none;
  border-left: 3px solid transparent;
  color: #cfe8e7;
  font-family: inherit;
  font-size: 11px;
  font-weight: 600;
  cursor: pointer;
}
.modulo-icone-emoji { font-size: 20px; }
.modulo-icone-rodape { margin-top: auto; }
.modulo-icone:hover { background: rgba(255,255,255,0.08); color: #fff; }
.modulo-icone.ativo { background: rgba(255,255,255,0.14); border-left-color: #ffd166; color: #fff; }

.modulo { flex: 1; min-height: 0; display: flex; flex-direction: column; }
.modulo-placeholder { padding: 24px; color: #666; }

#cadastros-tabs.tabs-strip {
  flex: 0 0 auto;
  display: flex;
  gap: 4px;
  padding: 0 20px;
  border-bottom: 1px solid #ddd;
  background: #fafbfb;
}
.tab-btn {
  padding: 10px 14px;
  background: none;
  border: none;
  border-bottom: 2px solid transparent;
  color: #666;
  font-family: inherit;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
}
.tab-btn:hover { color: #0f3d3e; }
.tab-btn.ativo { color: #0f3d3e; border-bottom-color: #0f3d3e; }
/* Reusada pelo conteudo do modulo Cadastros (#cadastros-conteudo) e do
   modulo Administracao (#administracao-conteudo) -- mesmo layout de area
   rolavel com padding, sem duplicar a regra. */
.modulo-conteudo { flex: 1; min-height: 0; overflow-y: auto; padding: 20px; max-width: 640px; }
.modulo-conteudo.largo { max-width: 1100px; }

/* Visao "CRUD" (estilo Django admin) das abas do modulo Cadastros --
   tabela real (colunas, linha por registro) em vez das linhas soltas
   ".modal-item" empilhadas com o form de criacao sempre aberto. */
.crud-toolbar { display: flex; justify-content: space-between; align-items: center; margin-bottom: 14px; }
.crud-toolbar h3 { margin: 0; }
.crud-table-wrap { overflow-x: auto; border: 1px solid #e3e6e6; border-radius: 8px; }
.crud-table { width: 100%; border-collapse: collapse; font-size: 13px; background: #fff; }
.crud-table th {
  text-align: left;
  padding: 10px 12px;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: .03em;
  color: #666;
  background: #f0f4f4;
  border-bottom: 1px solid #e3e6e6;
  white-space: nowrap;
}
.crud-table td { padding: 9px 12px; border-bottom: 1px solid #eee; vertical-align: middle; }
.crud-table tr:last-child td { border-bottom: none; }
.crud-table tbody tr:hover td { background: #fafbfb; }
.crud-table select { font-size: 12px; padding: 3px 4px; }
.crud-table .col-acoes { text-align: right; white-space: nowrap; }
.crud-table .col-acoes button + button { margin-left: 4px; }
.crud-vazio { padding: 20px !important; text-align: center; color: #999; }
.th-ordenar {
  background: none;
  border: none;
  color: inherit;
  font: inherit;
  text-transform: inherit;
  letter-spacing: inherit;
  padding: 0;
  cursor: pointer;
  white-space: nowrap;
}
.th-ordenar:hover { text-decoration: underline; }
.crud-paginacao {
  display: flex;
  justify-content: center;
  align-items: center;
  gap: 12px;
  margin-top: 10px;
  font-size: 12px;
  color: #666;
}
.badge { display: inline-block; padding: 2px 9px; border-radius: 10px; font-size: 11px; font-weight: 700; }
.badge-ativo { background: #dcfce7; color: #16a34a; }
.badge-inativo { background: #f1f1f1; color: #888; }
.btn-tabela { font-size: 12px; padding: 4px 10px; cursor: pointer; border-radius: 4px; border: 1px solid #ccc; background: #fff; }
.btn-tabela:hover { background: #f2f2f2; }
.btn-tabela.excluir { color: #b00020; border-color: #b00020; }
.btn-tabela.excluir:hover { background: #fdecec; }
.crud-form-toggle { margin-top: 18px; max-width: 640px; }
.btn-primario {
  margin-top: 16px;
  width: 100%;
  padding: 10px;
  background: #0f3d3e;
  color: #fff;
  border: none;
  border-radius: 4px;
  cursor: pointer;
  font-weight: 600;
}
.btn-primario:hover { background: #145453; }

#content { display: flex; flex: 1; min-height: 0; }

#sidebar {
  width: 360px;
  min-height: 0;
  padding: 14px;
  overflow-y: auto;
  border-right: 1px solid #ddd;
  background: #fafbfb;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.secao {
  background: #fff;
  border: 1px solid #e3e6e6;
  border-radius: 8px;
  overflow: hidden;
}
.secao summary {
  cursor: pointer;
  padding: 10px 14px;
  font-weight: 700;
  font-size: 13px;
  color: #0f3d3e;
  background: #f0f4f4;
  list-style: none;
  user-select: none;
}
.secao summary::-webkit-details-marker { display: none; }
.secao summary::after { content: "▾"; float: right; color: #999; transition: transform .15s; }
.secao[open] summary::after { transform: rotate(180deg); }
.secao summary:hover { background: #e5ebeb; }
.secao-corpo {
  padding: 14px;
  display: flex;
  flex-direction: column;
  gap: 14px;
  max-height: 45vh;
  overflow-y: auto;
}

.field label { display: block; font-weight: 600; margin-bottom: 6px; font-size: 13px; }
.field input, .field select { width: 100%; padding: 8px; border: 1px solid #ccc; border-radius: 4px; }
.field input:focus, .field select:focus { outline: none; border-color: #0f3d3e; box-shadow: 0 0 0 2px rgba(15,61,62,0.15); }
.field-checkbox { display: flex; flex-direction: row; flex-wrap: wrap; gap: 16px; }
.field-checkbox label { display: flex; align-items: center; gap: 6px; font-weight: 400; margin-bottom: 0; }
.field-checkbox input { width: auto; padding: 0; }

#search-results {
  list-style: none;
  margin: 4px 0 0;
  padding: 0;
  max-height: 160px;
  overflow-y: auto;
  border: 1px solid #eee;
}
#search-results li { padding: 6px 8px; cursor: pointer; font-size: 13px; }
#search-results li:hover { background: #f0f0f0; }

#waypoint-list { list-style: none; padding-left: 0; margin: 0; }
#waypoint-list li { margin-bottom: 8px; font-size: 13px; border: 1px solid #e9e9e9; border-radius: 6px; padding: 6px 8px; background: #fff; }
#waypoint-list li.waypoint-arrastando { opacity: 0.4; }
#waypoint-list li.waypoint-drop-alvo { border-color: #0f3d3e; border-style: dashed; }
#waypoint-list .waypoint-linha { display: flex; align-items: center; gap: 6px; }
#waypoint-list .waypoint-linha .waypoint-alca { cursor: grab; color: #999; user-select: none; }
#waypoint-list .waypoint-linha .waypoint-label { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
#waypoint-list .waypoint-linha .waypoint-numero { color: #666; font-weight: 600; font-size: 11px; }
#waypoint-list button { background: none; border: none; color: #b00020; cursor: pointer; }
.waypoint-toggle-btn { background: none; border: none; color: #0f3d3e; cursor: pointer; font-size: 11px; padding: 2px 4px; white-space: nowrap; }
.waypoint-toggle-btn:hover { text-decoration: underline; }
.waypoint-remover-btn { font-size: 14px; padding: 2px 4px; }
.waypoint-trecho-badge { display: inline-block; margin-top: 3px; font-size: 11px; padding: 1px 6px; border-radius: 8px; background: #eef6f6; color: #0f3d3e; }
.waypoint-coords { font-size: 11px; color: #888; margin-top: 3px; }
.waypoint-detalhes { display: none; }
.waypoint-detalhes.aberto { display: block; }
.waypoint-tempo-parada { display: flex; align-items: center; gap: 6px; margin-top: 3px; }
.waypoint-tempo-parada label { font-size: 11px; color: #666; font-weight: 400; margin: 0; white-space: nowrap; }
.waypoint-tempo-parada input { width: 60px; padding: 3px 6px; font-size: 12px; border: 1px solid #ccc; border-radius: 4px; }
.waypoint-janela { display: flex; flex-wrap: wrap; align-items: center; gap: 5px; margin-top: 3px; }
.waypoint-janela label { font-size: 11px; color: #666; font-weight: 400; margin: 0; width: 100%; }
.waypoint-janela span { font-size: 11px; color: #666; }
.waypoint-janela input { padding: 3px 4px; font-size: 11px; border: 1px solid #ccc; border-radius: 4px; }

#resultado { font-size: 13px; }
#resultado .linha { display: flex; justify-content: space-between; padding: 4px 0; border-bottom: 1px solid #eee; }
#resultado .total { font-weight: 700; }
#resultado .dica { color: #888; font-size: 12px; margin-top: 4px; border-bottom: none; }
#resultado .linha.alerta-piso { background: #fdecec; color: #b00020; font-weight: 700; padding: 6px 8px; border-radius: 4px; border-bottom: none; margin: 4px 0; }
#resultado .linha.ok-piso { background: #dcfce7; color: #16a34a; font-weight: 700; padding: 6px 8px; border-radius: 4px; border-bottom: none; margin: 4px 0; }
#resultado .dre { background: #f7f9f9; border-radius: 6px; padding: 8px 12px; margin-top: 8px; }
#resultado .jornada { background: #fff8ee; border-radius: 6px; padding: 8px 12px; margin-top: 8px; }
#resultado .linha-dre { font-size: 12px; padding: 2px 0; font-family: "SF Mono", Consolas, Menlo, monospace; }

.dre-tabela { width: 100%; border-collapse: collapse; font-size: 12px; margin-top: 4px; }
.dre-tabela td { padding: 4px 2px; border-bottom: 1px solid #e6e9e9; }
.dre-tabela td:last-child { text-align: right; white-space: nowrap; font-family: "SF Mono", Consolas, Menlo, monospace; }
.dre-linha-receita td { font-weight: 600; color: #0f3d3e; }
.dre-linha-custo td:last-child { color: #b00020; }
.dre-linha-imposto td { color: #b8860b; }
.dre-linha-imposto td:last-child { color: #b8860b; font-weight: 600; }
.dre-linha-informativo td { color: #999; font-style: italic; }
.dre-linha-total td { font-weight: 700; border-top: 2px solid #ccc; border-bottom: none; }
.dre-linha-margem td { font-weight: 700; }
.dre-linha-margem.dre-positivo td:last-child { color: #16a34a; }
.dre-linha-margem.dre-negativo td:last-child { color: #b00020; }
#resultado .aviso { color: #7a5c00; background: #fff6dd; padding: 8px; border-radius: 4px; margin-top: 8px; }
#resultado .erro { color: #b00020; background: #ffe3e3; padding: 8px; border-radius: 4px; margin-top: 8px; }

.botoes-secundarios { display: flex; flex-direction: column; gap: 8px; margin-top: 4px; }
button.secundario {
  width: 100%;
  padding: 8px;
  background: #fff;
  color: #0f3d3e;
  border: 1px solid #0f3d3e;
  border-radius: 4px;
  cursor: pointer;
  font-size: 12px;
  transition: background .15s;
}
button.secundario:hover { background: #eef4f4; }

#map { flex: 1; position: relative; min-width: 0; }

#resultado-painel {
  width: 360px;
  min-height: 0;
  padding: 14px;
  overflow-y: auto;
  border-left: 1px solid #ddd;
  background: #fafbfb;
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.resultado-vazio { color: #888; font-size: 13px; text-align: center; margin-top: 40px; }
#resultado-painel.tem-resultado .resultado-vazio { display: none; }

.label-com-acao { display: flex; justify-content: space-between; align-items: baseline; }
.link-btn {
  background: none; border: none; padding: 0; margin: 0;
  color: #0f3d3e; font-weight: 400; font-size: 11px; text-decoration: underline; cursor: pointer;
}

#map-toolbar { position: absolute; top: 10px; right: 10px; z-index: 500; }
#map-toolbar button {
  background: #fff; border: 1px solid #ccc; border-radius: 4px; padding: 6px 10px;
  font-size: 12px; cursor: pointer; box-shadow: 0 1px 3px rgba(0,0,0,0.2);
  transition: background .15s;
}
#map-toolbar button:hover { background: #f0f4f4; }

#map-legenda {
  position: absolute; bottom: 20px; left: 10px; z-index: 500;
  background: #fff; border-radius: 6px; padding: 8px 12px; font-size: 12px;
  box-shadow: 0 1px 3px rgba(0,0,0,0.2);
}
#map-legenda div { display: flex; align-items: center; gap: 6px; margin: 2px 0; }
#map-legenda .dica { color: #888; font-size: 11px; margin-top: 4px; }
.ponto-legenda { display: inline-block; width: 10px; height: 10px; border-radius: 50%; }
.ponto-legenda.ponto-parada { background: #3388ff; }
.ponto-legenda.ponto-pedagio { background: #b00020; }

.rota-arrastavel { cursor: copy; }
.icone-parada-descanso { font-size: 18px; text-align: center; line-height: 22px; }
.icone-bloqueio { font-size: 18px; text-align: center; line-height: 22px; }

.popup-remover-btn {
  background: #b00020; color: #fff; border: none; border-radius: 4px;
  padding: 6px 10px; font-size: 12px; cursor: pointer;
}
.popup-remover-btn:hover { background: #8f001a; }

/* Chegada/partida por waypoint (feature CT-e) -- popup do marker E lista
   lateral de paradas (renderWaypointList/_htmlSecoesChegadaPartida) */
.popup-cte-secao { display: flex; flex-direction: column; gap: 4px; margin-top: 6px; min-width: 220px; }
.popup-cte-secao label { font-size: 11px; color: #666; font-weight: 600; }
.popup-cte-secao select, .popup-cte-secao input { padding: 4px 6px; font-size: 12px; border: 1px solid #ccc; border-radius: 4px; }
.popup-salvar-cte-btn {
  background: #0f3d3e; color: #fff; border: none; border-radius: 4px;
  padding: 6px 10px; font-size: 12px; cursor: pointer; margin-top: 6px;
}
.popup-salvar-cte-btn:hover { background: #0a2c2d; }
.waypoint-chegada-partida { margin-top: 6px; padding-top: 6px; border-top: 1px dashed #ddd; }
.waypoint-chegada-partida .popup-cte-secao { min-width: 0; }

/* Diagrama de eixos/pneus (cadastro de Cavalos/Ônibus/Carretas) */
.diagrama-eixos { margin: 4px 0 8px; padding: 8px; background: #fafbfb; border: 1px solid #eee; border-radius: 6px; text-align: center; }
.diagrama-eixos-legenda { font-size: 11px; margin-top: 4px; }

#modal-overlay {
  position: fixed; inset: 0; background: rgba(0,0,0,0.5);
  display: flex; align-items: center; justify-content: center; z-index: 2000;
}
#modal-box {
  background: #fff; border-radius: 8px; padding: 24px; width: 480px; max-width: 90vw;
  max-height: 80vh; overflow-y: auto; position: relative;
}
#modal-fechar {
  position: absolute; top: 12px; right: 16px; background: none; border: none;
  font-size: 22px; cursor: pointer; color: #666; line-height: 1;
}
#modal-conteudo h3 { margin-top: 0; font-size: 16px; color: #0f3d3e; }
.modal-item { border-bottom: 1px solid #eee; padding: 10px 0; font-size: 13px; }
.modal-item .linha { display: flex; justify-content: space-between; align-items: center; }
.linha-faturamento { margin-top: 6px; font-size: 12px; color: #0f7a3d; display: flex; align-items: center; gap: 6px; }
.linha-faturamento input { flex: 1; padding: 4px 6px; font-size: 12px; border: 1px solid #ccc; border-radius: 4px; }
.linha-faturamento button { font-size: 11px; padding: 4px 8px; cursor: pointer; border-radius: 4px; border: 1px solid #0f3d3e; background: #fff; color: #0f3d3e; }
.modal-item button { font-size: 12px; padding: 3px 8px; margin-left: 6px; cursor: pointer; border-radius: 4px; border: 1px solid #ccc; background: #fff; }
.modal-item .excluir { color: #b00020; border-color: #b00020; }
.modal-form label { display: block; font-weight: 600; font-size: 12px; margin: 10px 0 4px; }
.modal-form input, .modal-form select { width: 100%; padding: 6px; border: 1px solid #ccc; border-radius: 4px; }

/* Combobox generico "buscar + criar inline" (criarCombobox em app.js) --
   posicionado relativo ao input pai, lista de resultados flutua por cima. */
.combobox-wrap { position: relative; }
.combobox-resultados {
  position: absolute; z-index: 20; top: 100%; left: 0; right: 0;
  background: #fff; border: 1px solid #ccc; border-top: none; border-radius: 0 0 4px 4px;
  max-height: 180px; overflow-y: auto; box-shadow: 0 4px 8px rgba(0,0,0,0.1);
}
.combobox-resultados.hidden { display: none; }
.combobox-item { padding: 6px 8px; font-size: 13px; cursor: pointer; }
.combobox-item:hover, .combobox-item.realcado { background: #eef5f4; }
.combobox-item.combobox-criar { color: #0f3d3e; font-weight: 600; border-top: 1px solid #eee; }
.combobox-sublabel { color: #666; font-size: 12px; }

/* ===== Layout mobile (<=768px) =====
   Pedido do usuario: as 3 colunas fixas de #content (sidebar 360px | mapa |
   resultado 360px) espremem o mapa ate' ficar inutilizavel em tela pequena.
   Abordagem: em vez de position:fixed pras barras novas, usa flex "em fluxo"
   (order na rail de modulos) -- o app ja e' todo desenhado em torno de
   .screen{height:100vh;overflow:hidden} com cada regiao tendo seu proprio
   overflow-y interno (comentario la' em cima), entao uma barra em fluxo ja
   "empurra" o conteudo sem duplicar altura como padding-bottom, e evita a
   dor de cabeca classica do Safari iOS (barra de URL dinamica nao bate
   sempre com 100vh pra elementos position:fixed). So' o dropdown do menu ≡
   e o FAB de calcular sao overlays de verdade (position:absolute), porque
   precisam flutuar por cima de conteudo, nao empurrar layout. */
@media (max-width: 768px) {
  /* --- rail de modulos vira barra inferior (so' precisa de `order`, sem
     position:fixed) --- */
  #app-body { flex-direction: column; }
  #modulos-rail {
    order: 1;
    width: 100%;
    flex-direction: row;
    justify-content: space-around;
    padding: 4px 0;
  }
  .modulo-icone { flex: 1; border-left: none; border-top: 3px solid transparent; }
  .modulo-icone.ativo { border-left-color: transparent; border-top-color: #ffd166; }
  .modulo-icone-rodape { margin-top: 0; } /* era o truque de "empurrar pro fim" do modo coluna -- sem efeito no modo linha */

  /* --- cabecalho: links secundarios + sair colapsam num dropdown ≡ --- */
  #saldo-box { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  .header-links { display: none; }
  #menu-hamburguer-btn {
    display: block; flex: 0 0 auto; background: none; border: none;
    color: #fff; font-size: 22px; cursor: pointer; padding: 4px 8px;
  }
  #header-menu-mobile {
    display: none; position: absolute; top: 100%; left: 0; right: 0;
    background: #0f3d3e; z-index: 1600; padding: 8px 20px 12px; box-shadow: 0 4px 8px rgba(0,0,0,0.2);
  }
  #header-menu-mobile.aberto { display: flex; flex-direction: column; gap: 8px; }
  #header-menu-mobile .header-links { display: flex; flex-direction: column; gap: 10px; }
  #header-menu-mobile #logout-btn { width: auto; align-self: flex-start; }

  /* --- modulo Roteirizacao: controle segmentado no topo + 1 painel por vez --- */
  #roteirizacao-mobile-tabs { display: flex; flex: 0 0 auto; border-bottom: 1px solid #ddd; }
  .mobile-tab-btn {
    flex: 1; padding: 10px 4px; background: #fff; border: none; border-bottom: 3px solid transparent;
    font-size: 13px; font-weight: 600; color: #666; cursor: pointer;
  }
  .mobile-tab-btn.ativo { color: #0f3d3e; border-bottom-color: #0f3d3e; }

  /* position:relative aqui (nao so' em #content) -- #calcular-btn-fab e'
     IRMAO de #content, nao filho, entao precisa que o proprio
     #modulo-roteirizacao seja o bloco de posicionamento. Achado real (bug
     relatado): sem isso, bottom:16px do FAB era medido a partir da tela
     INTEIRA (nenhum ancestral tinha position ate' o viewport), sobrepondo a
     barra inferior de modulos (que tambem fica "no fundo da tela"). Com
     #modulo-roteirizacao{position:relative}, o flexbox ja' faz o trabalho:
     esse modulo (flex:1 dentro de #app-body em coluna) tem sua altura
     limitada exatamente ate' onde a barra inferior comeca -- bottom:16px
     passa a significar "16px acima do topo da barra", nao "16px acima do
     fundo da tela", sem precisar adivinhar/hardcodar a altura da barra. */
  #modulo-roteirizacao { position: relative; }
  #content { flex-direction: column; }
  #sidebar, #map, #resultado-painel { display: none; width: 100%; border: none; }
  #sidebar.mobile-ver-ativo { display: flex; }
  #map.mobile-ver-ativo { display: block; } /* Leaflet nao e' flex container */
  #resultado-painel.mobile-ver-ativo { display: flex; }

  /* sidebar ocupa a tela inteira no mobile (nao mais uma coluna de 360px) --
     o teto de 45vh por secao aberta faz mais sentido como um teto generoso
     (a propria tela), nao um valor pensado pra caber ao lado do mapa. */
  .secao-corpo { max-height: none; }

  #calcular-btn-fab {
    display: block; position: absolute; bottom: 16px; right: 16px; z-index: 1050;
    border-radius: 24px; box-shadow: 0 2px 8px rgba(0,0,0,0.3);
  }
}
