/* Camada visual do sistema — Fase D.
 *
 * Um arquivo so, sem framework e sem build. O ARQUITETURA.md §1 fecha em HTML
 * no servidor; trazer Tailwind ou Bootstrap para quatro telas custaria uma
 * cadeia de build que o projeto nao tem e uma dependencia de CDN que o patio,
 * com internet ruim, nao perdoaria.
 *
 * Tres regras aqui nao sao estetica, sao funcionamento, e nenhuma delas pode
 * ser "limpada" depois:
 *
 *   1. alvo de toque de 48 px (a WCAG 2.5.5 pede 44; dedo com luva pede mais);
 *   2. `font-size: 16px` em todo campo — abaixo disso o iOS aplica zoom ao
 *      focar e desalinha a tela inteira, e o operador perde o lugar;
 *   3. `touch-action: none` no canvas da assinatura, senao o tablet rola em vez
 *      de desenhar. Esse e invisivel em teste de desktop.
 */

:root {
  --tinta: #1a1a1a;
  --tinta-fraca: #5f6368;
  --fundo: #f2f4f7;
  --superficie: #fff;
  --borda: #d8dce3;
  --borda-forte: #b6bcc7;
  --primaria: #0b57d0;
  --primaria-escura: #08429e;
  --erro: #b3261e;
  --erro-fundo: #fdecea;
  --ok: #1b6b3a;
  --ok-fundo: #e7f4ec;
  --alerta: #8a5a00;
  --alerta-fundo: #fff4e0;
  --raio: 10px;
  --sombra: 0 1px 2px rgb(16 24 40 / 6%), 0 1px 3px rgb(16 24 40 / 10%);
}

* { box-sizing: border-box; }

/* `hidden` tem de vencer o `display` das classes de botão — é assim que o
 * JavaScript liga e desliga os caminhos com e sem script. */
[hidden] { display: none !important; }

body {
  margin: 0;
  font: 16px/1.5 system-ui, -apple-system, "Segoe UI", sans-serif;
  color: var(--tinta);
  background: var(--fundo);
  -webkit-text-size-adjust: 100%;
}

h1 { font-size: 1.5rem; margin: 0 0 .25rem; }
h2 { font-size: 1.125rem; margin: 0 0 .75rem; }
a { color: var(--primaria); }

/* ── topo ─────────────────────────────────────────────────────────────────── */

.topo {
  display: flex;
  flex-wrap: wrap;
  gap: .75rem 1.25rem;
  justify-content: space-between;
  align-items: center;
  padding: .625rem 1rem;
  background: var(--superficie);
  border-bottom: 1px solid var(--borda);
}

.marca {
  font-weight: 700;
  text-decoration: none;
  color: inherit;
  letter-spacing: .08em;
}

.menu { display: flex; gap: .5rem; align-items: center; flex: 1; }
.menu a {
  display: inline-flex;
  align-items: center;
  min-height: 40px;
  padding: 0 .75rem;
  border-radius: var(--raio);
  text-decoration: none;
  font-weight: 500;
}
.menu a:hover { background: var(--fundo); }
.menu .botao-topo {
  background: var(--primaria);
  color: #fff;
}
.menu .botao-topo:hover { background: var(--primaria-escura); }

.sessao { display: flex; gap: 1rem; align-items: center; }
.usuario { color: var(--tinta-fraca); font-size: .875rem; }
.link {
  background: none; border: none; color: var(--primaria);
  cursor: pointer; font: inherit; padding: 0;
}

main { padding: 1.25rem 1rem 5rem; max-width: 60rem; margin: 0 auto; }

/* ── avisos ───────────────────────────────────────────────────────────────── */

.avisos { list-style: none; padding: 0; margin: 1rem auto 0; max-width: 60rem; }
.aviso {
  padding: .75rem 1rem;
  border-radius: var(--raio);
  border: 1px solid var(--borda);
  background: var(--superficie);
  margin-bottom: .5rem;
}
.aviso.success { background: var(--ok-fundo); border-color: #b7ddc6; color: var(--ok); }
.aviso.error { background: var(--erro-fundo); border-color: #f3c2bd; color: var(--erro); }
.aviso.warning { background: var(--alerta-fundo); border-color: #f0d9a8; color: var(--alerta); }

.erro { color: var(--erro); }
.nota { color: var(--tinta-fraca); font-size: .875rem; }

/* ── cartoes e secoes ─────────────────────────────────────────────────────── */

.cartao {
  background: var(--superficie);
  border: 1px solid var(--borda);
  border-radius: var(--raio);
  padding: 1.25rem;
  box-shadow: var(--sombra);
}
.cartao.estreito { max-width: 22rem; margin: 3rem auto; }

.secao {
  background: var(--superficie);
  border: 1px solid var(--borda);
  border-radius: var(--raio);
  padding: 1.25rem;
  margin-bottom: 1rem;
  box-shadow: var(--sombra);
}
.secao > h2 {
  display: flex;
  align-items: baseline;
  gap: .5rem;
  padding-bottom: .625rem;
  border-bottom: 1px solid var(--borda);
}
.secao > h2 .contagem { font-size: .8125rem; font-weight: 400; color: var(--tinta-fraca); }

/* ── formulario ───────────────────────────────────────────────────────────── */

label { display: block; margin: .875rem 0 .25rem; font-size: .875rem; font-weight: 500; }

input, select, textarea {
  width: 100%;
  /* 16px exatos: abaixo disso o iOS dá zoom ao focar. */
  font: 16px/1.4 inherit;
  font-family: inherit;
  padding: .625rem .75rem;
  min-height: 48px;
  border: 1px solid var(--borda-forte);
  border-radius: var(--raio);
  background: var(--superficie);
  color: inherit;
}
textarea { min-height: 5rem; resize: vertical; }
input:focus, select:focus, textarea:focus {
  outline: 2px solid var(--primaria);
  outline-offset: 1px;
  border-color: var(--primaria);
}

.campo-placa {
  font-size: 1.5rem;
  letter-spacing: .12em;
  text-transform: uppercase;
  font-weight: 600;
}

.dupla { display: grid; gap: 0 1rem; }
@media (min-width: 48rem) { .dupla { grid-template-columns: 1fr 1fr; } }

button[type=submit], .botao {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: .5rem;
  min-height: 48px;
  padding: .625rem 1.25rem;
  border: 1px solid transparent;
  border-radius: var(--raio);
  background: var(--primaria);
  color: #fff;
  font: inherit;
  font-weight: 500;
  text-decoration: none;
  cursor: pointer;
}
button[type=submit]:hover, .botao:hover { background: var(--primaria-escura); }
.botao.secundario {
  background: var(--superficie);
  color: var(--tinta);
  border-color: var(--borda-forte);
}
.botao.secundario:hover { background: var(--fundo); }
.botao.perigo { background: var(--erro); }
.botao-largo { width: 100%; }

/* Nivel de combustivel: radios viram cinco botoes. Funciona sem JavaScript. */
.botoes-nivel { display: flex; gap: .5rem; flex-wrap: wrap; }
.botoes-nivel label {
  margin: 0;
  flex: 1 1 5rem;
}
.botoes-nivel input { position: absolute; opacity: 0; pointer-events: none; }
.botoes-nivel .rotulo {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 48px;
  padding: 0 .5rem;
  border: 1px solid var(--borda-forte);
  border-radius: var(--raio);
  background: var(--superficie);
  cursor: pointer;
  font-weight: 500;
}
.botoes-nivel input:checked + .rotulo {
  background: var(--primaria);
  border-color: var(--primaria);
  color: #fff;
}
.botoes-nivel input:focus-visible + .rotulo { outline: 2px solid var(--primaria); outline-offset: 2px; }

/* ── fotos ────────────────────────────────────────────────────────────────── */

.grade-fotos {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(9rem, 1fr));
  gap: .75rem;
}

.slot-foto {
  position: relative;
  border: 2px dashed var(--borda-forte);
  border-radius: var(--raio);
  background: var(--fundo);
  overflow: hidden;
  min-height: 8.5rem;
  display: flex;
  flex-direction: column;
}
.slot-foto.preenchido { border-style: solid; border-color: var(--ok); background: var(--superficie); }
.slot-foto .rotulo-slot {
  padding: .375rem .5rem;
  font-size: .8125rem;
  font-weight: 500;
  text-align: center;
  background: var(--superficie);
  border-bottom: 1px solid var(--borda);
}
.slot-foto .area {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 6rem;
  cursor: pointer;
  color: var(--tinta-fraca);
  font-size: .8125rem;
  text-align: center;
  padding: .5rem;
}
.slot-foto img { width: 100%; height: 100%; object-fit: cover; display: block; }
.slot-foto .acoes {
  display: flex;
  gap: .25rem;
  padding: .25rem;
  border-top: 1px solid var(--borda);
  background: var(--superficie);
}
.slot-foto .acoes button, .slot-foto .acoes label {
  flex: 1; margin: 0;
  min-height: 40px;
  font-size: .8125rem;
  border-radius: 6px;
  border: 1px solid var(--borda);
  background: var(--superficie);
  color: var(--tinta);
  cursor: pointer;
  display: flex; align-items: center; justify-content: center;
}
.slot-foto .enviando { position: absolute; inset: 0; display: flex; align-items: center;
  justify-content: center; background: rgb(255 255 255 / 85%); font-size: .875rem; }
.slot-foto input[type=file] { position: absolute; opacity: 0; width: 0; height: 0; }

.selo-falta {
  display: inline-block;
  padding: .125rem .5rem;
  border-radius: 999px;
  font-size: .75rem;
  background: var(--alerta-fundo);
  color: var(--alerta);
  border: 1px solid #f0d9a8;
}

/* ── assinatura ───────────────────────────────────────────────────────────── */

.assinatura-registrada {
  display: flex;
  gap: 1rem;
  align-items: center;
  flex-wrap: wrap;
}
.assinatura-registrada img {
  max-width: 18rem; width: 100%;
  border: 1px solid var(--borda);
  border-radius: var(--raio);
  background: #fff;
}

dialog.painel {
  width: min(100vw, 60rem);
  max-width: 100%;
  border: none;
  border-radius: var(--raio);
  padding: 0;
}
dialog.painel::backdrop { background: rgb(0 0 0 / 55%); }
dialog.painel .corpo { padding: 1rem; }
dialog.painel .rodape { display: flex; gap: .5rem; padding: 0 1rem 1rem; flex-wrap: wrap; }
dialog.painel .rodape > * { flex: 1 1 8rem; }

#assinatura {
  width: 100%;
  height: min(45vh, 16rem);
  border: 1px dashed var(--borda-forte);
  border-radius: var(--raio);
  background: #fff;
  /* Sem isto o tablet rola e dá zoom em vez de desenhar. */
  touch-action: none;
  -webkit-user-select: none;
  user-select: none;
  overscroll-behavior: contain;
}

/* ── lista de ordens ──────────────────────────────────────────────────────── */

.chips { display: flex; gap: .5rem; flex-wrap: wrap; margin: 0 0 1rem; padding: 0; list-style: none; }
.chips a {
  display: inline-flex;
  align-items: center;
  gap: .375rem;
  min-height: 40px;
  padding: 0 .75rem;
  border: 1px solid var(--borda-forte);
  border-radius: 999px;
  background: var(--superficie);
  text-decoration: none;
  color: var(--tinta);
  font-size: .875rem;
}
.chips a.ativo { background: var(--primaria); border-color: var(--primaria); color: #fff; }
.chips .n { font-weight: 600; }

.selo-etapa {
  display: inline-flex;
  align-items: center;
  gap: .375rem;
  padding: .125rem .5rem;
  border-radius: 999px;
  font-size: .75rem;
  font-weight: 500;
  background: var(--fundo);
  border: 1px solid var(--borda);
  color: var(--tinta-fraca);
  white-space: nowrap;
}
.selo-etapa .numero {
  display: inline-flex; align-items: center; justify-content: center;
  width: 1.25rem; height: 1.25rem; border-radius: 50%;
  background: var(--primaria); color: #fff; font-size: .6875rem;
}

.lista-ordens { list-style: none; padding: 0; margin: 0; display: grid; gap: .75rem; }
.lista-ordens li {
  background: var(--superficie);
  border: 1px solid var(--borda);
  border-radius: var(--raio);
  padding: .875rem 1rem;
  display: grid;
  gap: .5rem;
  box-shadow: var(--sombra);
}
@media (min-width: 48rem) {
  .lista-ordens li { grid-template-columns: 1fr auto; align-items: center; }
}
.lista-ordens .identificacao { display: flex; flex-wrap: wrap; gap: .5rem; align-items: baseline; }
.lista-ordens .placa { font-size: 1.125rem; font-weight: 700; letter-spacing: .05em; }
.lista-ordens .numero-os { color: var(--tinta-fraca); font-size: .875rem; font-variant-numeric: tabular-nums; }
.lista-ordens .detalhe { color: var(--tinta-fraca); font-size: .875rem; }

.paginacao { display: flex; gap: .5rem; align-items: center; justify-content: center; margin-top: 1.25rem; }

.vazio { text-align: center; color: var(--tinta-fraca); padding: 2rem 1rem; }

/* ── veiculo achado na busca ──────────────────────────────────────────────── */

.achado { border: 1px solid var(--borda); border-radius: var(--raio); padding: 1rem; margin-bottom: .75rem; background: var(--superficie); }
.achado .placa { font-size: 1.375rem; font-weight: 700; letter-spacing: .06em; }
.achado .ja-aberta { background: var(--alerta-fundo); border: 1px solid #f0d9a8; color: var(--alerta);
  border-radius: var(--raio); padding: .625rem .75rem; margin: .75rem 0; font-size: .875rem; }

/* ── rodape fixo de acoes ─────────────────────────────────────────────────── */

.rodape-fixo {
  position: sticky;
  bottom: 0;
  display: flex;
  gap: .75rem;
  flex-wrap: wrap;
  padding: .75rem 0;
  margin-top: 1rem;
  background: linear-gradient(to top, var(--fundo) 70%, transparent);
}
.rodape-fixo > * { flex: 1 1 12rem; }

/* ── ficha (detalhe) ──────────────────────────────────────────────────────── */

.ficha { display: grid; gap: .25rem .75rem; margin: 0; }
@media (min-width: 36rem) { .ficha { grid-template-columns: max-content 1fr; } }
.ficha dt { color: var(--tinta-fraca); font-size: .875rem; }
.ficha dd { margin: 0 0 .5rem; }

.trilha { list-style: none; padding: 0; margin: 0; }
.trilha li { padding: .5rem 0; border-bottom: 1px solid var(--borda); font-size: .875rem; }
.trilha li:last-child { border-bottom: none; }
