/* Aba "Fluxo" da portaria (/cad), pelas maquetes aprovadas (docs/apresentacoes/fluxo-porteiro-app.html e
   fluxo-celular-subtelas.html). Tokens de tokens.css; cores de situação com nome: verde = autorizado/feito,
   âmbar = atenção (sem autorização, passou do prazo), vermelho = negar/alerta.
   Tablet e PC (≥ 900 px): a página não rola; ficha e subtelas à esquerda, listas à direita (só a lista rola).
   Celular: uma coluna, subtelas por cima, abas do Fluxo embaixo; também sem rolagem da página. */

.fx-app {
  --fx-g: clamp(8px, 1.1vh, 14px);
  --fx-ok: var(--green);
  --fx-am: var(--tipo-visitante);
  --fx-vm: var(--red-texto);
  --fx-pl-fundo: #F8FAFC;
  --fx-pl-texto: #0B1220;
  --fx-pl-borda: #CBD5E1;
  --fx-pl-faixa: #1D4ED8;
  font-size: clamp(14px, 1.7vh, 17px);
}

/* A página inteira cabe na tela com a aba Fluxo aberta: topo do app, aba, barra de abas */
body:has(#aba-fluxo:not([hidden])) { overflow: hidden; }
body:has(#aba-fluxo:not([hidden])) #tela-app { height: 100dvh; display: flex; flex-direction: column; }
body:has(#aba-fluxo:not([hidden])) main.tela {
  --fx-g: clamp(8px, 1.1vh, 14px);
  --fx-barra-abas: 66px; /* a barra de abas do app (Cadastrar · Sem cadastro · Fluxo), fixa embaixo */
  flex: 1; min-height: 0; max-width: none; width: 100%; display: flex;
  padding: var(--fx-g) var(--fx-g) calc(var(--fx-barra-abas) + env(safe-area-inset-bottom) + var(--fx-g));
}
.fx-app:not([hidden]) { flex: 1; min-height: 0; display: flex; flex-direction: column; gap: var(--fx-g); width: 100%; }

/* Topo: + Sem leitura · Pesquisar · Controle de veículos */
.fx-topo { display: flex; align-items: center; gap: var(--fx-g); flex: none; }
.fx-busca-botao {
  flex: 1; min-width: 0; min-height: 48px; display: flex; align-items: center; gap: 8px; padding: 0 14px;
  border-radius: 10px; border: 1px solid var(--border-campo); background: var(--bg-input); color: var(--text-secondary);
  font: inherit; text-align: left; cursor: pointer;
}
.fx-busca-texto { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.fx-semlei { flex: none; color: var(--link); border-color: var(--accent); }
.fx-controle { flex: none; }
.fx-faixas:empty, .fx-estado:empty { display: none; }
.fx-faixas { display: grid; gap: 6px; flex: none; }
.fx-estado { margin: 0; flex: none; }

/* Duas colunas no tablet/PC; só a lista e a subtela rolam por dentro */
.fx-trabalho { flex: 1; min-height: 0; display: grid; grid-template-columns: minmax(0, 1.5fr) minmax(0, 1fr); grid-template-rows: minmax(0, 1fr); gap: var(--fx-g); }
.fx-destaque {
  min-height: 0; overflow: hidden; display: flex; flex-direction: column; gap: calc(var(--fx-g) * 0.8);
  background: var(--bg-card); border: 1px solid var(--border); border-radius: 16px; padding: var(--fx-g);
}
.fx-mov { min-height: 0; display: grid; grid-template-rows: auto minmax(0, 1fr) auto; gap: var(--fx-g); }
.fx-lista { list-style: none; margin: 0; padding: 0 4px 0 0; overflow-y: auto; min-height: 0; display: grid; gap: calc(var(--fx-g) * 0.7); align-content: start; }
.fx-lista-fila { max-height: 30vh; }
.fx-rodape { margin: 0; color: var(--text-secondary); font-size: 0.85em; text-align: center; }
.fx-rodape:empty { display: none; }

/* Abas do Fluxo */
.fx-abas { display: grid; grid-template-columns: repeat(auto-fit, minmax(7.2em, 1fr)); gap: 6px; }
.fx-abas button {
  min-height: 44px; padding: 4px 6px; border-radius: 10px; border: 1px solid var(--border); background: none;
  color: var(--text-secondary); font: inherit; font-size: 0.88em; font-weight: 700; cursor: pointer; line-height: 1.15;
}
.fx-abas button[aria-selected="true"] { background: var(--tint-accent); border-color: var(--accent); color: var(--text-primary); }
.fx-abas i { font-style: normal; margin-left: 4px; padding: 0 6px; border-radius: 999px; background: var(--bg-input); font-variant-numeric: tabular-nums; }
.fx-abas [aria-selected="true"] i { background: var(--accent-botao); color: #fff; }

/* Placa no desenho Mercosul */
.fx-pl { display: inline-flex; flex-direction: column; width: max-content; border: 2px solid var(--fx-pl-borda); border-radius: 6px; overflow: hidden; background: var(--fx-pl-fundo); color: var(--fx-pl-texto); vertical-align: middle; }
.fx-pl i { display: block; height: 5px; background: var(--fx-pl-faixa); }
.fx-pl b { font: 800 1em/1.15 var(--font-mono); letter-spacing: 0.07em; padding: 2px 9px 3px; }
.fx-pl-g { border-width: 3px; border-radius: 8px; }
.fx-pl-g i { height: 7px; }
.fx-pl-g b { font-size: clamp(22px, 4vh, 40px); }
.fx-pl-vazia b { color: var(--text-muted); font-family: var(--font-sans); letter-spacing: 0; }

/* Itens das listas */
.fx-it {
  width: 100%; display: grid; grid-template-columns: auto 1fr auto; gap: 10px; align-items: center; text-align: left;
  background: var(--bg-card); border: 1px solid var(--border); border-radius: 12px; padding: 10px; color: var(--text-primary); font: inherit; cursor: pointer;
}
li.fx-it { cursor: default; grid-template-columns: 1fr; }
.fx-it:not(:has(.fx-it-foto)) { grid-template-columns: 1fr auto; }
.fx-it:hover { border-color: var(--border-realce); }
.fx-it:focus-visible, .fx-b:focus-visible, .fx-c:focus-visible, .fx-op:focus-visible, .fx-chip:focus-visible, .fx-abas button:focus-visible { outline: 3px solid var(--accent); outline-offset: 2px; }
.fx-it-sel { border-color: var(--accent); box-shadow: inset 0 0 0 1px var(--accent); }
.fx-it-venc { border-color: color-mix(in srgb, var(--fx-am) 60%, transparent); }
.fx-it-ok { border-color: color-mix(in srgb, var(--fx-ok) 50%, transparent); }
.fx-it-foto { width: clamp(72px, 8vw, 112px); aspect-ratio: 5 / 3; object-fit: cover; border-radius: 8px; background: var(--bg-input); display: grid; place-items: center; font-size: 0.75em; color: var(--text-muted); }
.fx-it-txt { display: flex; flex-direction: column; gap: 3px; min-width: 0; }
.fx-it-txt > :first-child { align-self: flex-start; }
.fx-it small, .fx-m { color: var(--text-secondary); }
.fx-it small { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.fx-it time { color: var(--text-secondary); font-size: 0.85em; font-variant-numeric: tabular-nums; }
.fx-it-negado .fx-pl, .fx-it-cancelado .fx-pl { opacity: 0.75; }
.fx-am { color: var(--fx-am) !important; }
.fx-ok { color: var(--fx-ok) !important; }
.fx-app em { font-style: normal; color: var(--fx-ok); }

/* Selos de situação */
.fx-selo { display: inline-block; width: max-content; max-width: 100%; padding: 0.3em 0.8em; border-radius: 999px; font-weight: 800; font-size: 0.85em; }
.fx-selo-am { background: color-mix(in srgb, var(--fx-am) 15%, transparent); color: var(--fx-am); border: 1px solid color-mix(in srgb, var(--fx-am) 40%, transparent); }
.fx-selo-vd { background: color-mix(in srgb, var(--fx-ok) 15%, transparent); color: var(--fx-ok); border: 1px solid color-mix(in srgb, var(--fx-ok) 45%, transparent); }
.fx-selo-vm { background: color-mix(in srgb, var(--fx-vm) 15%, transparent); color: var(--fx-vm); border: 1px solid color-mix(in srgb, var(--fx-vm) 45%, transparent); }

/* Ficha: cabeçalho, foto ao lado dos dados, campos em 3 colunas, botões no pé */
.fx-cab { display: flex; justify-content: space-between; align-items: baseline; gap: 8px; flex: none; }
.fx-cab small { color: var(--text-secondary); }
.fx-rot { font-size: 0.72em; font-weight: 800; letter-spacing: 0.09em; text-transform: uppercase; color: var(--text-secondary); }
.fx-leitura { flex: 1 1 auto; min-height: 72px; display: grid; grid-template-columns: minmax(0, 1.15fr) minmax(0, 1fr); gap: var(--fx-g); }
.fx-foto { width: 100%; height: 100%; min-height: 0; object-fit: cover; border-radius: 12px; background: var(--bg-input); display: grid; place-items: center; color: var(--text-muted); }
.fx-sub-corpo > .fx-foto { height: clamp(90px, 18vh, 200px); flex: none; }
.fx-dados { display: flex; flex-direction: column; gap: calc(var(--fx-g) * 0.6); min-height: 0; overflow: hidden; }
.fx-hist { color: var(--text-secondary); border-top: 1px solid var(--border); padding-top: 6px; }
div.fx-hist { display: flex; flex-direction: column; gap: 2px; }
div.fx-hist small { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.fx-campos { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: calc(var(--fx-g) * 0.6) var(--fx-g); flex: none; }
.fx-c {
  display: flex; flex-direction: column; gap: 2px; min-width: 0; padding: 0.35em 0.6em; border: 0; border-bottom: 2px solid var(--border-campo);
  background: none; color: var(--text-primary); font: inherit; text-align: left; border-radius: 6px 6px 0 0;
}
button.fx-c { cursor: pointer; min-height: 48px; }
.fx-c-l { grid-column: span 2; }
.fx-c small { color: var(--text-secondary); font-size: 0.72em; font-weight: 800; letter-spacing: 0.04em; }
.fx-c span, .fx-c input, .fx-c select { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.fx-c input, .fx-c select {
  width: 100%; min-height: 32px; border: 0; padding: 0; background: transparent; color: var(--text-primary); font: inherit;
}
.fx-c input::placeholder, .fx-v { color: var(--text-muted); font-style: italic; }
.fx-c select option { background: var(--bg-card); color: var(--text-primary); }
.fx-c:focus-within { border-bottom-color: var(--accent); background: var(--tint-accent); }
.fx-c-erro { border-bottom-color: var(--fx-vm); background: var(--tint-red); }
.fx-c-dest { border-bottom-color: var(--accent); background: var(--tint-accent); }
.fx-erro, .fx-erro-geral, .fx-erro-t { color: var(--fx-vm); font-weight: 700; font-size: 0.85em; white-space: normal !important; margin: 0; }
.fx-num { display: inline-grid; place-items: center; width: 1.4em; height: 1.4em; border-radius: 50%; background: var(--accent-botao); color: #fff; font-size: 0.9em; }
.fx-troca { color: var(--link); font-weight: 700; }
.fx-placa-dig { font: 800 1.5em var(--font-mono) !important; letter-spacing: 0.08em; text-transform: uppercase; }

.fx-acoes { display: grid; grid-template-columns: 1fr 2fr; gap: var(--fx-g); flex: none; }
.fx-acoes:empty { display: none; }
.fx-acoes-col, .fx-acoes:has(> :only-child) { grid-template-columns: 1fr; }
.fx-b {
  display: flex; align-items: center; justify-content: center; gap: 6px; min-height: clamp(48px, 6.4vh, 64px); padding: 0 1em;
  border-radius: 12px; border: 1px solid var(--border-campo); background: none; color: var(--text-primary);
  font: inherit; font-weight: 800; cursor: pointer; text-align: center; touch-action: manipulation;
}
.fx-b:disabled { opacity: 0.5; cursor: default; }
.fx-b-p { background: var(--accent-botao); border-color: var(--accent-botao); color: #fff; font-size: 1.08em; }
.fx-b-p:hover { background: var(--accent-botao-hover); }
.fx-b-n { color: var(--fx-vm); }
.fx-b-n.fx-cheio { background: var(--tint-red); border-color: var(--fx-vm); }
.fx-b-s { color: var(--text-secondary); font-weight: 700; }
.fx-b:active { transform: scale(0.98); }
.fx-largo { width: 100%; }
.fx-link { background: none; border: 0; color: var(--link); font: inherit; font-weight: 700; cursor: pointer; min-height: 44px; padding: 0 6px; }
.fx-rodape-ficha { display: flex; justify-content: space-between; align-items: center; gap: 8px; flex: none; }
.fx-rodape-ficha:empty { display: none; }
.fx-nav { display: flex; align-items: center; gap: 4px; color: var(--text-secondary); margin-left: auto; }

/* Avisos e faixas */
.fx-faixa { display: flex; flex-direction: column; gap: 2px; padding: 8px 12px; border-radius: 10px; font-weight: 700; }
.fx-faixa small { font-weight: 600; }
button.fx-faixa { width: 100%; text-align: left; font: inherit; font-weight: 700; color: inherit; cursor: pointer; }
.fx-faixa-vm { background: var(--tint-red); border: 1px solid var(--fx-vm); color: var(--text-primary); }
.fx-faixa-am { background: var(--tint-amber, rgba(250,204,21,0.12)); border: 1px solid var(--fx-am); color: var(--text-primary); }
.fx-faixa-ok { flex-direction: row; align-items: center; justify-content: space-between; gap: 8px; background: var(--tint-green); border: 1px solid var(--fx-ok); }
.fx-aviso-am { padding: 8px 12px; border-radius: 10px; background: var(--tint-amber, rgba(250,204,21,0.12)); border: 1px solid var(--fx-am); }
.fx-nova { display: flex; align-items: center; gap: 6px; padding: 6px 10px; border-radius: 10px; border: 1px solid var(--accent); background: var(--tint-accent); color: var(--text-primary); font: inherit; cursor: pointer; }
.fx-vazio { border: 1px dashed var(--border-campo); border-radius: 12px; padding: 22px 14px; text-align: center; color: var(--text-secondary); }

/* Subtelas */
.fx-sub-topo { display: flex; align-items: center; gap: 8px; flex: none; }
.fx-sub-topo h3 { margin: 0; font-size: 1.1em; }
.fx-volta { min-width: 44px; min-height: 44px; border: 0; background: none; color: var(--link); font-size: 1.6em; cursor: pointer; }
.fx-sub-corpo { display: flex; flex-direction: column; gap: calc(var(--fx-g) * 0.8); min-height: 0; flex: 1; }
.fx-rolagem { overflow-y: auto; min-height: 0; }
.fx-busca { width: 100%; min-height: 48px; padding: 0 12px; border-radius: 10px; border: 1px solid var(--accent); background: var(--bg-input); color: var(--text-primary); font: inherit; }
.fx-op { display: block; width: 100%; text-align: left; min-height: 44px; padding: 8px 12px; border: 0; border-bottom: 1px solid var(--border); background: none; color: var(--text-primary); font: inherit; cursor: pointer; }
.fx-op[aria-pressed="true"] { background: var(--tint-accent); border-radius: 8px; }
.fx-op-tudo { color: var(--link); font-weight: 700; }
.fx-chips { display: flex; flex-wrap: wrap; gap: 6px; }
.fx-chip { min-height: 44px; padding: 0 14px; border-radius: 999px; border: 1px solid var(--border-campo); background: none; color: var(--text-primary); font: inherit; cursor: pointer; }
.fx-chip[aria-pressed="true"] { background: var(--tint-accent); border-color: var(--accent); font-weight: 700; }
.fx-lin { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.fx-centro { justify-content: center; }
.fx-folha { display: grid; background: var(--bg-input); border: 1px solid var(--border-campo); border-radius: 12px; padding: 6px; }
.fx-folha-t { padding: 6px 10px; color: var(--text-secondary); font-variant-numeric: tabular-nums; }
.fx-folha .fx-op:last-child { border: 0; }
.fx-seg { display: grid; grid-template-columns: 1fr 1fr; gap: 4px; padding: 4px; border-radius: 10px; background: var(--bg-input); }
.fx-seg button, .fx-dias button { min-height: 44px; border: 0; border-radius: 8px; background: none; color: var(--text-secondary); font: inherit; font-weight: 700; cursor: pointer; }
.fx-seg [aria-pressed="true"], .fx-dias [aria-pressed="true"] { background: var(--accent-botao); color: #fff; }
.fx-dias { grid-column: 1 / -1; display: grid; grid-template-columns: repeat(7, 1fr); gap: 4px; }
.fx-dias button { border: 1px solid var(--border-campo); }
.fx-chk { display: flex; align-items: center; gap: 8px; font-weight: 700; min-height: 44px; }
.fx-chk input { width: 22px; height: 22px; }

/* Fim único (A): sinal grande, resumo, barra de 6 s e Desfazer */
.fx-feito { display: flex; flex-direction: column; align-items: center; gap: 8px; text-align: center; border-radius: 16px; padding: 18px 14px; }
.fx-feito-ok { background: var(--tint-green); border: 1px solid var(--fx-ok); }
.fx-feito-nao { background: var(--tint-red); border: 1px solid var(--fx-vm); }
.fx-feito b { font-size: 1.35em; }
.fx-check { width: 64px; height: 64px; border-radius: 50%; display: grid; place-items: center; font-size: 34px; font-weight: 900; color: #fff; }
.fx-check.fx-ok { background: #16A34A; color: #fff !important; }
.fx-check.fx-nao { background: #DC2626; }
.fx-barra { width: 100%; height: 6px; border-radius: 3px; background: var(--bg-input); overflow: hidden; }
.fx-barra span { display: block; height: 100%; background: var(--fx-ok); transform-origin: left; animation: fx-encolhe var(--fx-resta, 6000ms) linear forwards; }
.fx-feito-nao .fx-barra span { background: var(--fx-vm); }
@keyframes fx-encolhe { from { transform: scaleX(1); } to { transform: scaleX(0); } }
.fx-grande { min-height: 56px; }

/* Controle de veículos (tabela de hoje) */
.fx-tabela-rolagem { overflow: auto; min-height: 0; flex: 1; }
.fx-tabela { border-collapse: collapse; width: 100%; font-size: 0.85em; }
.fx-tabela th, .fx-tabela td { padding: 6px 8px; text-align: left; border-bottom: 1px solid var(--border); white-space: nowrap; }
.fx-tabela th { color: var(--text-secondary); position: sticky; top: 0; background: var(--bg-card); }

/* Telas baixas de tablet: foto menor, campos mais justos */
@media (min-width: 900px) and (max-height: 820px) {
  .fx-app { font-size: 14px; }
  .fx-b { min-height: 46px; }
  button.fx-c { min-height: 42px; }
  .fx-c input, .fx-c select { min-height: 26px; }
}

/* Celular e tablet em pé: uma coluna; subtela por cima da lista; abas do Fluxo embaixo */
@media (max-width: 899px) {
  .fx-trabalho { grid-template-columns: 1fr; grid-template-rows: minmax(0, 1fr) auto; }
  .fx-mov { grid-template-rows: minmax(0, 1fr) auto auto; }
  .fx-mov #fx-abas { order: 3; }
  .fx-app[data-ver="lista"] .fx-destaque { display: none; }
  .fx-app[data-ver="lista"] .fx-trabalho { grid-template-rows: minmax(0, 1fr); }
  .fx-app[data-ver="trabalho"] .fx-mov { grid-template-rows: auto; }
  .fx-app[data-ver="trabalho"] #fx-lista, .fx-app[data-ver="trabalho"] #fx-rodape { display: none; }
  .fx-destaque { overflow-y: auto; padding: 10px; }
  .fx-leitura { grid-template-columns: 1fr; flex: none; }
  .fx-leitura .fx-foto { height: clamp(80px, 13vh, 140px); }
  .fx-dados { flex-direction: row; flex-wrap: wrap; align-items: center; }
  .fx-dados > small { flex-basis: 100%; }
  /* Negar e Liberar sempre à vista: grudados no pé da ficha enquanto os campos rolam */
  .fx-destaque > .fx-acoes { position: sticky; bottom: -10px; z-index: 1; padding: 8px 0 10px; background: var(--bg-card); }
  .fx-campos { grid-template-columns: 1fr 1fr; }
  .fx-c-cel { grid-column: span 2; }
  .fx-busca-texto { display: none; }
  .fx-busca-botao { flex: none; width: 48px; justify-content: center; padding: 0; }
  .fx-topo { justify-content: flex-end; }
  .fx-abas { grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 4px; }
  .fx-abas button { font-size: 0.78em; padding: 4px 2px; }
  .fx-abas i { display: block; width: max-content; margin: 2px auto 0; }
}
@media (prefers-reduced-motion: reduce) { .fx-barra span { animation: none; } .fx-b:active { transform: none; } }
