:root {
  --grafite: #2b2f36;
  --grafite-2: #3a3f47;
  --azul: #1f4e79;
  --azul-claro: #2f6fb0;
  --laranja: #e67e22;
  --laranja-esc: #cf6f18;
  --ok: #1e8e5a;
  --defeito: #c0392b;
  --cinza: #6b7280;
  --cinza-claro: #eef1f4;
  --linha: #d7dbe0;
  --fundo: #f4f6f8;
  --branco: #ffffff;
  --radius: 14px;
  --sombra: 0 2px 10px rgba(20,25,35,.08);
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; padding: 0; }
body {
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  background: var(--fundo);
  color: var(--grafite);
  font-size: 16px;
  padding-bottom: env(safe-area-inset-bottom);
}

/* ---------- Topbar ---------- */
.topbar {
  position: sticky; top: 0; z-index: 50;
  display: flex; align-items: center; justify-content: space-between;
  gap: 12px; padding: 12px 16px;
  background: var(--grafite); color: #fff;
  padding-top: calc(12px + env(safe-area-inset-top));
}
.brand { display: flex; align-items: center; gap: 10px; cursor: pointer; }
.brand-logo { width: 34px; height: 34px; border-radius: 8px; object-fit: cover; }
.brand-nome { font-weight: 800; font-size: 18px; letter-spacing: .3px; }
.brand-sub { font-size: 11px; color: #b9c0ca; margin-top: -2px; }
.btn-ghost { background: transparent; border: 1px solid rgba(255,255,255,.25); color: #fff;
  padding: 7px 12px; border-radius: 10px; font-size: 14px; }

/* ---------- Layout ---------- */
main { max-width: 720px; margin: 0 auto; padding: 16px; }
.loading { text-align: center; color: var(--cinza); padding: 40px 0; }
.view { animation: fade .18s ease; }
@keyframes fade { from { opacity: 0; transform: translateY(4px); } to { opacity: 1; transform: none; } }

h2.view-titulo { font-size: 20px; margin: 4px 0 16px; }
.muted { color: var(--cinza); font-size: 14px; }

/* ---------- Botoes ---------- */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  border: none; border-radius: 12px; padding: 14px 18px; font-size: 16px; font-weight: 700;
  cursor: pointer; width: 100%; }
.btn-primary { background: var(--laranja); color: #fff; }
.btn-primary:active { background: var(--laranja-esc); }
.btn-azul { background: var(--azul); color: #fff; }
.btn-azul:active { background: var(--azul-claro); }
.btn-sec { background: #fff; color: var(--grafite); border: 1.5px solid var(--linha); }
.btn-linha { display: flex; gap: 10px; }
.btn-linha .btn { flex: 1; }

/* ---------- FAB ---------- */
.fab { position: fixed; right: 18px; bottom: calc(18px + env(safe-area-inset-bottom));
  background: var(--laranja); color: #fff; border: none; border-radius: 999px;
  padding: 15px 22px; font-size: 16px; font-weight: 800; box-shadow: 0 6px 18px rgba(230,126,34,.4);
  z-index: 40; }

/* ---------- Cards / lista ---------- */
.card { background: #fff; border-radius: var(--radius); box-shadow: var(--sombra);
  padding: 16px; margin-bottom: 12px; }
.lista-item { display: flex; align-items: center; gap: 12px; text-decoration: none; color: inherit; }
.lista-item .ícone, .lista-item .icone { font-size: 26px; }
.lista-item .info { flex: 1; min-width: 0; }
.lista-item .info .t { font-weight: 700; }
.lista-item .info .s { font-size: 13px; color: var(--cinza); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.badge { font-size: 11px; font-weight: 700; padding: 3px 9px; border-radius: 999px; white-space: nowrap; }
.lixeira { border: none; background: transparent; font-size: 18px; padding: 6px; margin-left: 2px; cursor: pointer; opacity: .55; }
.lixeira:active, .lixeira:hover { opacity: 1; }

/* Login, usuários e auditoria */
.login-view { max-width: 420px; margin: 0 auto; }
#user-chip { position: relative; margin-left: auto; }
#user-chip + #btn-voltar { margin-left: 8px; }
.user-menu { position: absolute; right: 0; top: 110%; background: #fff; border: 1px solid var(--borda, #ddd); border-radius: 10px; box-shadow: 0 6px 18px rgba(0,0,0,.12); display: flex; flex-direction: column; min-width: 170px; z-index: 50; overflow: hidden; }
.user-menu[hidden] { display: none; } /* sem isto, o display:flex acima vence o atributo hidden e o menu fica preso aberto */
.user-menu button { border: none; background: none; text-align: left; padding: 12px 14px; font-size: 15px; cursor: pointer; }
.user-menu button:active, .user-menu button:hover { background: #f2f4f7; }
.btn-mini { font-size: 13px; padding: 6px 10px; }
.usuario-card { display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 12px 14px; }
.usuario-card .acoes { display: flex; gap: 6px; flex-shrink: 0; }
.audit-linha { padding: 10px 14px; }
.audit-linha .quando { font-size: 12px; color: var(--cinza, #6b7280); }
.mini { font-size: 12px; }

/* Alertas de devolução na home */
.alertas { display: flex; flex-direction: column; gap: 8px; margin-bottom: 14px; }
.alerta { display: block; padding: 10px 14px; border-radius: 10px; text-decoration: none; color: inherit; font-size: 14px; border-left: 5px solid; }
.alerta .mini { display: block; color: var(--cinza, #6b7280); margin-top: 2px; }
.alerta.vencida { background: #fdecea; border-color: #c0392b; }
.alerta.vencida b { color: #c0392b; }
.alerta.proxima { background: #fff4e6; border-color: #e07b00; }
.alerta.proxima b { color: #b35c00; }

/* Status da frota */
.badge.st-disp { background: #d7f0e2; color: var(--ok, #1e8e5a); }
.badge.st-loc { background: #fdecd2; color: var(--laranja-esc, #b35c00); }
.badge.st-manu { background: #e8e8ec; color: #555; }

/* "na entrega: ..." — comparativo mostrado na vistoria de coleta */
.na-entrega { display: block; font-size: 12px; color: var(--cinza, #6b7280); margin: -2px 0 5px; }
.na-entrega .bom { color: var(--ok, #1e8e5a); }
.na-entrega .ruim { color: #c0392b; }
.badge.rascunho { background: #fdecd2; color: var(--laranja-esc); }
.badge.finalizada { background: #d7f0e2; color: var(--ok); }
.badge.entrega { background: #dae7f4; color: var(--azul); }
.badge.coleta { background: #efe1f7; color: #7d3ba8; }
.vazio { text-align: center; color: var(--cinza); padding: 48px 16px; }
.vazio .big { font-size: 40px; margin-bottom: 8px; }

/* ---------- Escolha de equipamento ---------- */
.grid-escolha { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.opcao { background: #fff; border: 2px solid var(--linha); border-radius: var(--radius);
  padding: 20px 12px; text-align: center; cursor: pointer; }
.opcao.sel { border-color: var(--laranja); background: #fff7ef; }
.opcao .emoji { font-size: 34px; }
.opcao-img { width: 100%; height: 96px; object-fit: contain; display: block; }
.opcao .nome { font-weight: 700; font-size: 14px; margin-top: 8px; }
.lista-img { width: 48px; height: 48px; object-fit: contain; border-radius: 8px; background: #fff; flex-shrink: 0; }
.seg { display: flex; background: var(--cinza-claro); border-radius: 12px; padding: 4px; margin: 8px 0 4px; }
.seg button { flex: 1; border: none; background: transparent; padding: 12px; border-radius: 9px;
  font-weight: 700; color: var(--cinza); font-size: 15px; }
.seg button.sel { background: #fff; color: var(--grafite); box-shadow: var(--sombra); }

/* ---------- Formulario / secoes ---------- */
.secao { background: #fff; border-radius: var(--radius); box-shadow: var(--sombra); margin-bottom: 12px; overflow: hidden; }
.secao-head { display: flex; align-items: center; justify-content: space-between; gap: 8px;
  padding: 14px 16px; background: var(--azul); color: #fff; cursor: pointer; }
.secao-head .tit { font-weight: 700; font-size: 15px; }
.secao-head .prog { font-size: 12px; color: #cfe0f2; }
.secao-body { padding: 6px 16px 14px; }
.campo { padding: 12px 0; border-bottom: 1px solid var(--linha); }
.campo:last-child { border-bottom: none; }
.campo label { display: block; font-weight: 600; font-size: 14px; margin-bottom: 6px; }
.campo .obs { font-weight: 400; color: var(--cinza); font-size: 12px; }
.req { color: var(--defeito); }
.campo input[type=text], .campo input[type=number], .campo input[type=date], .campo select, .campo textarea {
  width: 100%; border: 1.5px solid var(--linha); border-radius: 10px; padding: 12px;
  font-size: 16px; font-family: inherit; background: #fff; }
.campo textarea { min-height: 72px; resize: vertical; }
.campo input:focus, .campo select:focus, .campo textarea:focus { outline: none; border-color: var(--azul-claro); }

/* OK / Defeito / NA */
.tri { display: flex; gap: 8px; }
.tri button { flex: 1; border: 1.5px solid var(--linha); background: #fff; padding: 11px 6px;
  border-radius: 10px; font-weight: 700; font-size: 14px; color: var(--cinza); }
.tri button.sel-ok { background: var(--ok); color: #fff; border-color: var(--ok); }
.tri button.sel-def { background: var(--defeito); color: #fff; border-color: var(--defeito); }
.tri button.sel-na { background: var(--cinza); color: #fff; border-color: var(--cinza); }

/* Fotos */
.fotos-wrap { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 6px; }
.foto-thumb { position: relative; width: 84px; height: 84px; border-radius: 10px; overflow: hidden; border: 1px solid var(--linha); }
.foto-thumb img { width: 100%; height: 100%; object-fit: cover; }
.foto-thumb .x { position: absolute; top: 2px; right: 2px; background: rgba(0,0,0,.6); color: #fff;
  border: none; border-radius: 999px; width: 22px; height: 22px; font-size: 13px; }
.foto-add { width: 84px; height: 84px; border: 2px dashed var(--azul-claro); border-radius: 10px;
  background: #f3f8fd; color: var(--azul); display: flex; flex-direction: column; align-items: center;
  justify-content: center; font-size: 12px; font-weight: 700; gap: 2px; }
.foto-add .cam { font-size: 22px; }

/* Assinatura */
.assinatura-box { border: 1.5px dashed var(--linha); border-radius: 12px; background: #fff; }
#assinatura-canvas { width: 100%; height: 180px; touch-action: none; display: block; border-radius: 12px; }

/* Rodape fixo do form */
.form-actions { margin: 18px 0 90px; }

/* Pronto */
.pronto { text-align: center; padding: 24px 8px; }
.pronto .check { font-size: 56px; }
.pronto h2 { margin: 8px 0; }

.toast { position: fixed; left: 50%; transform: translateX(-50%); bottom: 90px;
  background: var(--grafite); color: #fff; padding: 12px 18px; border-radius: 999px;
  font-size: 14px; z-index: 100; box-shadow: var(--sombra); opacity: 0; transition: opacity .2s; }
.toast.show { opacity: 1; }
.erro-inline { color: var(--defeito); font-size: 12px; margin-top: 4px; }
