:root {
  --azul: #13294b;
  --azul-2: #1f3f70;
  --laranja: #f07f1a;
  --laranja-escuro: #c9620a;
  --fundo: #f2f4f7;
  --cartao: #ffffff;
  --texto: #1c2430;
  --texto-2: #5b6573;
  --borda: #dde2e9;
  --perigo: #c62828;
  --ok: #2e7d32;
  --raio: 14px;
  --sombra: 0 1px 2px rgba(16, 24, 40, .06), 0 2px 8px rgba(16, 24, 40, .06);
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  background: var(--fundo);
  color: var(--texto);
  font-size: 16px;
  line-height: 1.4;
}
a { color: inherit; text-decoration: none; }
button, input, select, textarea { font: inherit; color: inherit; }
[hidden] { display: none !important; }

/* ---------- Topo ---------- */
.topo {
  position: sticky; top: 0; z-index: 10;
  display: flex; align-items: center; gap: 4px;
  min-height: 56px; padding: 0 6px; padding-top: env(safe-area-inset-top);
  background: var(--azul); color: #fff;
  box-shadow: 0 2px 6px rgba(0, 0, 0, .15);
}
.topo-titulo {
  flex: 1; margin: 0 8px; font-size: 18px; font-weight: 650;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.topo-botao {
  width: 44px; height: 44px; border: 0; border-radius: 10px;
  background: transparent; color: #fff; display: grid; place-items: center; cursor: pointer;
}
.topo-botao:active { background: rgba(255, 255, 255, .15); }

.menu {
  position: fixed; top: 58px; right: 8px; z-index: 20;
  background: var(--cartao); border-radius: var(--raio); box-shadow: 0 8px 30px rgba(0, 0, 0, .2);
  min-width: 230px; overflow: hidden;
}
.menu a, .menu button {
  display: block; width: 100%; padding: 14px 18px; text-align: left;
  border: 0; background: none; cursor: pointer; font-size: 16px;
}
.menu a:hover, .menu button:hover { background: var(--fundo); }
.menu .menu-usuario { padding: 14px 18px; font-size: 14px; color: var(--texto-2); border-bottom: 1px solid var(--borda); }

/* ---------- Conteúdo ---------- */
.conteudo { max-width: 760px; margin: 0 auto; padding: 16px 16px 48px; }
.conteudo.largo { max-width: 1180px; }
.secao { font-size: 15px; text-transform: uppercase; letter-spacing: .04em; color: var(--texto-2); margin: 24px 0 10px; }
.secao:first-child { margin-top: 8px; }
.dica { color: var(--texto-2); font-size: 14px; }
.vazio {
  text-align: center; color: var(--texto-2); padding: 28px 16px;
  background: var(--cartao); border-radius: var(--raio); border: 1px dashed var(--borda);
}
.cartao { background: var(--cartao); border-radius: var(--raio); box-shadow: var(--sombra); padding: 16px; margin-bottom: 14px; }
.cartao > h3 { display: flex; align-items: center; gap: 8px; margin: 0 0 14px; font-size: 17px; }

/* ---------- Busca e filtros ---------- */
.busca { position: relative; margin-bottom: 12px; }
.busca input {
  width: 100%; height: 50px; padding: 0 16px 0 46px;
  border: 1px solid var(--borda); border-radius: 12px; background: var(--cartao); font-size: 17px;
}
.busca input:focus { outline: 2px solid var(--laranja); border-color: transparent; }
.busca svg { position: absolute; left: 15px; top: 15px; color: var(--texto-2); }

.filtros { display: flex; gap: 8px; overflow-x: auto; padding-bottom: 4px; margin-bottom: 12px; scrollbar-width: none; }
.filtro {
  flex: none; padding: 8px 14px; border-radius: 999px; border: 1px solid var(--borda); background: var(--cartao);
  font-size: 14px; font-weight: 600; cursor: pointer; white-space: nowrap;
}
.filtro small { color: var(--texto-2); font-weight: 500; margin-left: 4px; }
.filtro.ativo { background: var(--azul); border-color: var(--azul); color: #fff; }
.filtro.ativo small { color: #c7d3e6; }

.barra-wialon { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-bottom: 12px; font-size: 13px; color: var(--texto-2); }

.alerta {
  display: flex; align-items: center; gap: 12px; margin-bottom: 12px; padding: 12px 14px; border-radius: 12px;
  background: #fff4e5; border: 1px solid #f5c98b; color: #7a4300; font-size: 14px;
}
.alerta strong { display: block; font-size: 15px; }
.alerta .botao { flex: none; }

/* ---------- Lista ---------- */
.lista { background: var(--cartao); border-radius: var(--raio); box-shadow: var(--sombra); overflow: hidden; }
.item {
  display: flex; align-items: center; gap: 12px; padding: 13px 16px; min-height: 58px;
  border-bottom: 1px solid var(--borda);
}
.item:last-child { border-bottom: 0; }
.item:active, a.item:hover { background: #f8f9fb; }
.item-texto { flex: 1; min-width: 0; }
.item-texto strong { display: block; overflow-wrap: anywhere; }
.item-texto small { display: block; color: var(--texto-2); font-size: 13px; margin-top: 2px; }
.seta { color: var(--texto-2); flex: none; }
.item-texto small.achado-em { color: var(--azul-2); font-weight: 600; }
/* Modo "selecionar várias" (preenchimento em lote) */
.item.selecionavel { cursor: pointer; }
.item.selecionavel:has(.marca:checked) { background: #fff7ef; }
.marca { width: 24px; height: 24px; flex: none; accent-color: var(--laranja); }
.dica-selecao {
  display: flex; align-items: center; gap: 10px; flex-wrap: wrap; margin-bottom: 12px; padding: 12px 14px;
  border-radius: 12px; background: #e7eefb; color: var(--azul-2); font-size: 14px;
}
.dica-selecao .botao { flex: none; }
.barra-lote {
  position: sticky; bottom: 0; z-index: 5; display: flex; align-items: center; justify-content: space-between; gap: 10px; flex-wrap: wrap;
  margin: 12px -16px -48px; padding: 12px 16px calc(12px + env(safe-area-inset-bottom));
  background: var(--cartao); border-top: 1px solid var(--borda); box-shadow: 0 -4px 14px rgba(16, 24, 40, .08);
}
.barra-lote .botao { flex: 1 1 220px; }
.link { border: 0; background: none; padding: 0; color: var(--azul-2); text-decoration: underline; cursor: pointer; font-size: inherit; }
.lote-lista { display: flex; flex-wrap: wrap; gap: 6px; margin: 10px 0; }
.lote-regras { margin: 10px 0 0; padding-left: 20px; }
.lote-regras li { margin: 3px 0; }
.mais { text-align: center; padding: 12px; font-size: 14px; color: var(--texto-2); }

.selo {
  display: inline-block; flex: none; font-size: 12px; font-weight: 700; padding: 3px 9px; border-radius: 999px;
  background: #fff1e4; color: var(--laranja-escuro); white-space: nowrap; vertical-align: 1px;
}
.selo.verde { background: #e3f4ea; color: #1d6b3a; }
.selo.cinza { background: var(--fundo); color: var(--texto-2); }
.selo.vermelho { background: #fde8e8; color: #a61b1b; }
.selo.azul { background: #e7eefb; color: var(--azul-2); }
.selos { display: flex; flex-wrap: wrap; gap: 4px; margin-top: 5px; }

/* ---------- Botões e formulários ---------- */
.botao {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  min-height: 50px; padding: 0 20px; border: 0; border-radius: 12px; cursor: pointer;
  background: var(--laranja); color: #fff; font-weight: 700; font-size: 16px;
}
.botao:active { background: var(--laranja-escuro); }
.botao:disabled { opacity: .6; cursor: default; }
.botao.largo { width: 100%; }
.botao.secundario { background: var(--cartao); color: var(--azul); border: 1px solid var(--borda); }
.botao.pequeno { min-height: 38px; padding: 0 12px; font-size: 14px; }
.botao.perigo { background: transparent; color: var(--perigo); border: 1px solid #f1c6c6; }
.linha-botoes { display: flex; gap: 8px; flex-wrap: wrap; }

.campo { margin-bottom: 18px; }
.campo:last-child { margin-bottom: 0; }
.campo > label, .campo > .rotulo { display: block; font-weight: 650; margin-bottom: 8px; }
.campo input[type=text], .campo input[type=password], .campo input[type=date], .campo input[type=tel], .campo select, .campo textarea {
  width: 100%; min-height: 48px; padding: 10px 14px;
  border: 1px solid var(--borda); border-radius: 12px; background: #fff; font-size: 16px;
}
.campo textarea { min-height: 100px; resize: vertical; }
.campo input:focus, .campo select:focus, .campo textarea:focus { outline: 2px solid var(--laranja); border-color: transparent; }
.linha { display: flex; gap: 10px; }
.linha > * { flex: 1; min-width: 0; }
@media (max-width: 480px) { .linha.quebra { flex-direction: column; gap: 0; } }
.check { display: flex; align-items: center; gap: 10px; font-weight: 600 !important; cursor: pointer; }
.check input { width: 22px; height: 22px; flex: none; }

/* Opções grandes para tocar (rádio escondido) */
.opcoes { display: grid; grid-template-columns: repeat(auto-fit, minmax(120px, 1fr)); gap: 8px; }
.opcao {
  position: relative; display: flex; align-items: center; justify-content: center; gap: 8px;
  min-height: 50px; padding: 10px 12px; text-align: center;
  border: 2px solid var(--borda); border-radius: 12px; background: #fff; cursor: pointer; font-weight: 600;
}
.opcao input { position: absolute; opacity: 0; pointer-events: none; }
.opcao:has(input:checked) { border-color: var(--laranja); background: #fff7ef; color: var(--laranja-escuro); }
.opcao:has(input:focus-visible) { outline: 2px solid var(--azul-2); }
.opcoes.sim-nao { grid-template-columns: 1fr 1fr; max-width: 320px; }
/* Tipo de bloqueio: textos longos, alinhados à esquerda com o ícone */
.opcoes.lista-opcoes { grid-template-columns: repeat(auto-fit, minmax(230px, 1fr)); }
.opcoes.lista-opcoes .opcao { justify-content: flex-start; text-align: left; font-weight: 500; }

/* Parte que só aparece quando a resposta é "Sim" */
.extra { margin-top: 12px; padding: 14px; border-left: 4px solid var(--laranja); background: #fffaf5; border-radius: 0 12px 12px 0; }

/* Contatos */
.contato-editor { display: grid; grid-template-columns: 1fr 1fr 1fr auto; gap: 8px; align-items: center; margin-bottom: 8px; }
.contato-editor .contato-email { grid-column: 1 / 4; }
.contato a { color: var(--azul-2); text-decoration: underline; margin-right: 8px; }
.contato-editor input { min-height: 44px; padding: 8px 12px; border: 1px solid var(--borda); border-radius: 10px; min-width: 0; font-size: 15px; }
.contato-editor input:focus { outline: 2px solid var(--laranja); border-color: transparent; }
.botao-x { width: 40px; height: 40px; border-radius: 50%; border: 1px solid #f1c6c6; background: #fff; color: var(--perigo); cursor: pointer; font-size: 16px; }
@media (max-width: 560px) {
  .contato-editor { grid-template-columns: 1fr auto; padding: 10px; border: 1px solid var(--borda); border-radius: 12px; }
  .contato-editor input { grid-column: 1; }
  .contato-editor .botao-x { grid-column: 2; grid-row: 1; }
  .contato-editor .contato-email { grid-column: 1; }
}

/* Fotos e áudios */
.fotos { display: grid; grid-template-columns: repeat(auto-fill, minmax(92px, 1fr)); gap: 8px; margin-bottom: 10px; }
.fotos:empty { display: none; }
.foto { position: relative; aspect-ratio: 1; border-radius: 10px; overflow: hidden; background: var(--fundo); }
.foto img { width: 100%; height: 100%; object-fit: cover; display: block; cursor: zoom-in; }
.foto.nova { outline: 3px solid var(--laranja); outline-offset: -3px; }
.remover {
  position: absolute; top: 4px; right: 4px; width: 30px; height: 30px; border-radius: 50%;
  border: 0; background: rgba(0, 0, 0, .65); color: #fff; cursor: pointer; font-size: 15px;
}
.botoes-foto { display: flex; gap: 8px; flex-wrap: wrap; }
.botoes-foto .botao { flex: 1; min-width: 140px; }
.audios { display: grid; gap: 8px; margin-bottom: 10px; }
.audios:empty { display: none; }
.audio { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; padding: 8px; border: 1px solid var(--borda); border-radius: 12px; background: #fff; }
.audio.nova { border-color: var(--laranja); }
.audio audio { flex: 1 1 200px; width: 100%; min-width: 0; height: 40px; }
.audio .remover { position: static; flex: none; }
.gravando { display: flex; align-items: center; gap: 10px; padding: 10px 14px; border-radius: 12px; background: #fde8e8; color: #a61b1b; font-weight: 700; margin-bottom: 10px; }
.gravando::before { content: ""; width: 12px; height: 12px; border-radius: 50%; background: #d32f2f; animation: piscar 1s infinite; }
@keyframes piscar { 50% { opacity: .2; } }

/* Botão salvar sempre à mostra */
.salvar-fixo {
  position: sticky; bottom: 0; z-index: 5; margin: 0 -16px; padding: 12px 16px calc(12px + env(safe-area-inset-bottom));
  background: linear-gradient(to top, var(--fundo) 70%, rgba(242, 244, 247, 0));
}

/* ---------- Tela da unidade ---------- */
.cabecalho-unidade h2 { margin: 0 0 4px; font-size: 21px; overflow-wrap: anywhere; }
.dados-grade { display: grid; grid-template-columns: repeat(auto-fill, minmax(170px, 1fr)); gap: 10px 16px; margin-top: 12px; }
.dado small { display: block; font-size: 12px; color: var(--texto-2); font-weight: 600; text-transform: uppercase; letter-spacing: .03em; }
.dado span { display: block; overflow-wrap: anywhere; }
.dado.vazio-dado span { color: #9aa3ae; font-style: italic; }
.texto-livre { white-space: pre-wrap; background: var(--fundo); border-radius: 10px; padding: 10px 12px; margin: 10px 0 0; }
.rodape-ficha { font-size: 13px; color: var(--texto-2); margin: 4px 2px 14px; }
.cartao.desativada { border: 2px solid var(--perigo); }
.cartao.com-avaria { border: 2px solid #f5c98b; background: #fffaf2; }

.contatos-lista { display: grid; gap: 8px; margin-top: 12px; }
.contato { display: flex; align-items: center; gap: 10px; padding: 10px 12px; background: var(--fundo); border-radius: 10px; }
.contato .item-texto small { margin: 0; }
.contato a.botao { flex: none; }

/* Dados antigos do Wialon */
.antigos summary { cursor: pointer; font-weight: 700; list-style: none; display: flex; align-items: center; gap: 8px; }
.antigos summary::-webkit-details-marker { display: none; }
.antigos summary::after { content: "▾"; margin-left: auto; color: var(--texto-2); }
.antigos[open] summary::after { content: "▴"; }
.antigos-lista { margin: 12px 0 0; padding: 0; list-style: none; font-size: 14px; }
.antigos-lista li { padding: 7px 0; border-bottom: 1px solid var(--borda); overflow-wrap: anywhere; }
.antigos-lista li:last-child { border-bottom: 0; }
.antigos-lista b { color: var(--azul-2); }
.antigos .dica { margin: 8px 0 0; }

/* Histórico */
.historico { list-style: none; margin: 12px 0 0; padding: 0; }
.historico > li { position: relative; padding: 0 0 14px 18px; border-left: 2px solid var(--borda); margin-left: 6px; }
.historico > li::before { content: ""; position: absolute; left: -7px; top: 3px; width: 12px; height: 12px; border-radius: 50%; background: var(--laranja); }
.historico > li:last-child { padding-bottom: 0; }
.historico .quem { font-size: 14px; font-weight: 700; }
.historico .quem small { font-weight: 500; color: var(--texto-2); }
.historico ul { margin: 4px 0 0; padding-left: 16px; font-size: 14px; }
.historico li li { margin: 2px 0; overflow-wrap: anywhere; }
.historico .antes { color: #a61b1b; text-decoration: line-through; }
.historico .depois { color: #1d6b3a; font-weight: 600; }

/* Tela de editar: formulário + dados antigos lado a lado no computador */
.editor { display: grid; gap: 16px; }
.editor .lateral { order: -1; } /* no celular, os dados antigos ficam em cima (fechados) */
@media (min-width: 980px) {
  .editor { grid-template-columns: minmax(0, 1fr) 360px; align-items: start; }
  .editor .lateral { order: 0; position: sticky; top: 72px; max-height: calc(100vh - 90px); overflow: auto; }
  .editor .lateral .antigos summary { pointer-events: none; }
  .editor .lateral .antigos summary::after { content: none; }
}

/* ---------- Multas ---------- */
.item-botao { border: 0; background: none; padding: 0; text-align: left; cursor: pointer; font: inherit; color: inherit; }
.item.habilitado { border-left: 4px solid var(--ok); }
.item .problema { color: #a61b1b; font-weight: 600; }
.item .nome-unidade { font-weight: 500; color: var(--texto-2); font-size: 13px; display: inline; }
.marcar-todos { min-height: 44px; background: var(--fundo); cursor: pointer; }
.tabela { width: 100%; border-collapse: collapse; margin-top: 10px; font-size: 14px; }
.tabela th, .tabela td { text-align: left; padding: 7px 6px; border-bottom: 1px solid var(--borda); }
.tabela th { color: var(--texto-2); font-size: 12px; text-transform: uppercase; }
.faturamento { margin-bottom: 12px; }

/* Janela (configurar plano) */
.janela { border: 0; border-radius: var(--raio); padding: 0; width: min(520px, calc(100% - 24px)); max-height: calc(100% - 24px); box-shadow: 0 12px 40px rgba(0, 0, 0, .3); }
.janela::backdrop { background: rgba(16, 24, 40, .5); }
.janela form { padding: 18px; overflow: auto; }
.janela h3 { margin: 0 0 6px; font-size: 18px; }
.janela .linha .campo:last-child { margin-bottom: 18px; }
.janela select { width: 100%; min-height: 48px; padding: 10px 14px; border: 1px solid var(--borda); border-radius: 12px; background: #fff; font-size: 16px; }

/* ---------- Varredura de chips ---------- */
.resultado-chip { border-left: 4px solid var(--ok); }
.resultado-chip.nao-achou { border-left-color: var(--perigo); }
.resultado-chip h3 { font-family: Consolas, monospace; font-size: 17px; margin: 0 0 8px; }
.achado { display: block; padding: 10px 12px; background: var(--fundo); border-radius: 10px; margin-top: 8px; }
.achado strong { overflow-wrap: anywhere; }
.achado small { display: block; color: var(--texto-2); font-size: 13px; margin-top: 2px; overflow-wrap: anywhere; }
.resumo-varredura { display: flex; gap: 10px; flex-wrap: wrap; margin-bottom: 12px; }
.resumo-varredura .cartao { flex: 1; min-width: 150px; margin: 0; text-align: center; }
.resumo-varredura strong { display: block; font-size: 28px; }

/* ---------- Login ---------- */
.entrada { max-width: 400px; margin: 5vh auto 0; }
.entrada-marca { text-align: center; margin-bottom: 22px; }
.entrada-marca .icone { font-size: 52px; }
.entrada-logo { display: block; width: 100%; max-width: 220px; height: auto; margin: 0 auto 10px; border-radius: 16px; box-shadow: var(--sombra); }
.entrada-marca h2 { margin: 8px 0 4px; font-size: 24px; }
.entrada-marca p { margin: 0; color: var(--texto-2); }

/* ---------- Admin ---------- */
.usuario-linha { display: flex; align-items: center; gap: 10px; padding: 12px 0; border-bottom: 1px solid var(--borda); flex-wrap: wrap; }
.usuario-linha:last-child { border-bottom: 0; }
.usuario-linha .item-texto { min-width: 160px; }
.inativo { opacity: .5; }
.abas-usuario { flex-basis: 100%; display: flex; flex-wrap: wrap; align-items: center; gap: 6px 14px; padding-top: 4px; }
.abas-usuario > small { color: var(--texto-2); font-weight: 600; }
.aba-check { font-weight: 500 !important; font-size: 14px; }
.aba-check input { width: 18px; height: 18px; }
.campo .aba-check { margin-right: 14px; display: inline-flex; }

/* ---------- Avisos, carregando, visor de fotos ---------- */
.aviso {
  position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%); z-index: 50;
  max-width: calc(100% - 32px); padding: 14px 20px; border-radius: 12px;
  background: var(--texto); color: #fff; box-shadow: 0 8px 24px rgba(0, 0, 0, .25);
}
.aviso.erro { background: var(--perigo); }
.aviso.ok { background: var(--ok); }

.carregando { text-align: center; padding: 48px 16px; color: var(--texto-2); }
.giro {
  width: 36px; height: 36px; margin: 0 auto 14px; border-radius: 50%;
  border: 4px solid var(--borda); border-top-color: var(--laranja); animation: girar .8s linear infinite;
}
@keyframes girar { to { transform: rotate(360deg); } }

.visor { position: fixed; inset: 0; z-index: 60; background: rgba(0, 0, 0, .92); display: grid; place-items: center; padding: 16px; }
.visor img { max-width: 100%; max-height: 100%; object-fit: contain; }
.visor-fechar {
  position: absolute; top: 12px; right: 12px; width: 48px; height: 48px; border-radius: 50%;
  border: 0; background: rgba(255, 255, 255, .15); color: #fff; font-size: 22px; cursor: pointer;
}
