:root {
  --bg: #0e1117;
  --panel: #161b24;
  --panel-2: #1d2430;
  --linha: #2a3340;
  --texto: #e7ecf3;
  --muted: #8a97a8;
  --accent: #3b82f6;
  --c-res: #8a97a8;
  --c-fab: #e0a93a;
  --c-trans: #e8833a;
  --c-obra: #3b82f6;
  --c-inst: #22c55e;
  --c-canc: #f87171;
  --radio: 12px;
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--bg);
  color: var(--texto);
  font-family: "Segoe UI", system-ui, -apple-system, sans-serif;
  font-size: 15px;
  line-height: 1.4;
}
#app { max-width: 920px; margin: 0 auto; padding: 0 16px 48px; }

/* ---------- Cabeçalho ---------- */
.topo { display: flex; align-items: center; justify-content: space-between; gap: 16px; padding: 18px 4px 14px; flex-wrap: wrap; }
.topo-empresa { font-weight: 700; letter-spacing: .3px; }
.topo-app { color: var(--muted); font-size: 12px; text-transform: uppercase; letter-spacing: 1.5px; }
.contadores { display: flex; gap: 10px; flex-wrap: wrap; margin-bottom: 14px; }
.contador { min-width: 64px; text-align: center; background: var(--panel); border: 1px solid var(--linha); border-radius: 10px; padding: 6px 8px; }
.contador-num { font-size: 20px; font-weight: 700; color: var(--cor); }
.contador-lbl { font-size: 10px; color: var(--muted); letter-spacing: .3px; }
.link { background: none; border: none; color: var(--accent); cursor: pointer; font-size: 12px; padding: 0 4px; }
.badge-fila { display: inline-block; background: rgba(224,169,58,.16); color: var(--c-fab); border-radius: 20px; padding: 1px 8px; font-size: 10px; letter-spacing: .5px; margin-left: 6px; text-transform: none; }

/* ---------- Abas ---------- */
.abas { display: flex; gap: 4px; border-bottom: 1px solid var(--linha); margin-bottom: 18px; overflow-x: auto; }
.aba { background: none; border: none; color: var(--muted); cursor: pointer; padding: 10px 18px; font-size: 13px; letter-spacing: 1px; text-transform: uppercase; border-bottom: 2px solid transparent; margin-bottom: -1px; white-space: nowrap; }
.aba:hover { color: var(--texto); }
.aba.ativa { color: var(--accent); border-bottom-color: var(--accent); }

/* ---------- Cartões / formulário ---------- */
.cartao { background: var(--panel); border: 1px solid var(--linha); border-radius: var(--radio); padding: 18px; margin-bottom: 16px; }
.cartao-cab { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 14px; flex-wrap: wrap; }
.cartao h2 { font-size: 15px; margin: 0; }
.dica { color: var(--muted); font-size: 12px; }
.badge { background: var(--panel-2); color: var(--muted); border-radius: 20px; padding: 1px 9px; font-size: 12px; margin-left: 6px; }

.form-linha { display: flex; gap: 12px; align-items: flex-end; flex-wrap: wrap; }
.campo { display: flex; flex-direction: column; gap: 6px; font-size: 12px; color: var(--muted); flex: 1; min-width: 180px; }
.campo-curto { flex: 0 0 150px; min-width: 150px; }
select, input { background: var(--panel-2); border: 1px solid var(--linha); color: var(--texto); border-radius: 8px; padding: 10px 12px; font-size: 14px; width: 100%; }
select:focus, input:focus { outline: none; border-color: var(--accent); }

.btn-primario, .btn-secundario { border-radius: 8px; padding: 10px 16px; font-size: 14px; cursor: pointer; border: 1px solid transparent; white-space: nowrap; }
.btn-primario { background: var(--accent); color: #fff; }
.btn-primario:hover { filter: brightness(1.08); }
.btn-secundario { background: var(--panel-2); color: var(--texto); border-color: var(--linha); }
.btn-secundario:hover { border-color: var(--accent); }
.btn-primario:disabled, .btn-secundario:disabled, .btn-perigo:disabled { opacity: .5; cursor: default; filter: none; }
.btn-grande { font-size: 18px; padding: 16px 22px; width: 100%; margin-top: 14px; }
.btn-etq { background: none; border: 1px solid var(--linha); color: var(--texto); border-radius: 8px; padding: 7px 12px; cursor: pointer; font-size: 13px; }
.btn-etq:hover { border-color: var(--accent); color: var(--accent); }
.btn-excluir { background: none; border: 1px solid var(--linha); color: var(--muted); border-radius: 8px; padding: 7px 10px; cursor: pointer; font-size: 14px; }
.btn-excluir:hover { border-color: var(--c-canc); color: var(--c-canc); }
.btn-perigo { background: rgba(248,113,113,.12); color: var(--c-canc); border: 1px solid rgba(248,113,113,.45); border-radius: 8px; padding: 10px 16px; cursor: pointer; font-size: 14px; }
.btn-perigo:hover { background: rgba(248,113,113,.22); }
.config-acoes { display: flex; gap: 10px; flex-wrap: wrap; margin-top: 18px; }

/* ---------- Lista de peças ---------- */
.lista { display: flex; flex-direction: column; gap: 8px; }
.vazio { color: var(--muted); text-align: center; padding: 22px; }
.item { display: flex; align-items: center; gap: 14px; background: var(--panel-2); border: 1px solid var(--linha); border-radius: 10px; padding: 10px 14px; flex-wrap: wrap; }
.item-img { width: 44px; height: 44px; border-radius: 8px; overflow: hidden; background: #fff; flex: 0 0 44px; display: flex; align-items: center; justify-content: center; }
.item-img img { width: 100%; height: 100%; object-fit: contain; }
.item-img.sem-img { background: #0c1018; }
.item-img.sem-img::after { content: "📦"; font-size: 20px; }
.item-img.sem-img img { display: none; }
.item.clicavel { cursor: pointer; }
.item.clicavel:hover { border-color: var(--accent); }
.item-info { flex: 1; min-width: 160px; }
.item-id { font-weight: 700; font-family: ui-monospace, "Consolas", monospace; letter-spacing: .5px; }
.item-tipo { color: var(--muted); font-size: 13px; }
.item-acoes { display: flex; gap: 6px; }
.item-status { font-size: 11px; font-weight: 700; letter-spacing: .3px; padding: 3px 9px; border-radius: 20px; white-space: nowrap; }
.status-reservada { background: rgba(138,151,168,.18); color: var(--c-res); }
.status-fabricada { background: rgba(224,169,58,.16); color: var(--c-fab); }
.status-expedida { background: rgba(232,131,58,.16); color: var(--c-trans); }
.status-em_obra { background: rgba(59,130,246,.16); color: var(--c-obra); }
.status-instalada { background: rgba(34,197,94,.16); color: var(--c-inst); }
.status-cancelada, .status-remarcada { background: rgba(248,113,113,.16); color: var(--c-canc); }
.status-observacao { background: rgba(138,151,168,.18); color: var(--texto); }
.status-corrigida { background: rgba(224,169,58,.16); color: var(--c-fab); }
.status-reativada { background: rgba(34,197,94,.16); color: var(--c-inst); }

/* ---------- Marcar ---------- */
.ble { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.ble-dot { width: 10px; height: 10px; border-radius: 50%; background: var(--muted); flex: 0 0 10px; }
.ble-dot.on { background: var(--c-inst); box-shadow: 0 0 8px var(--c-inst); }
.log { font-family: ui-monospace, Consolas, monospace; font-size: 12px; color: var(--muted); white-space: pre-wrap; margin: 10px 0 0; max-height: 120px; overflow: auto; }
.marcar-atual { background: var(--panel-2); border: 1px solid var(--linha); border-radius: 10px; padding: 14px; margin-top: 14px; }
.linha-grande { font-family: ui-monospace, "Consolas", monospace; font-size: 30px; font-weight: 700; letter-spacing: 1px; word-break: break-all; margin: 6px 0; }
.marcar-estado { font-size: 13px; color: var(--muted); }
.marcar-estado.ok { color: var(--c-inst); }
.marcar-estado.falha { color: var(--c-canc); }
.marcar-acoes { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 12px; }
.ble-card { padding: 12px 18px; }
.ble-dot { width: 14px; height: 14px; flex-basis: 14px; }
.peca-dados { display: flex; flex-wrap: wrap; gap: 4px 8px; align-items: baseline; }
.peca-dados span { color: var(--muted); font-size: 10px; text-transform: uppercase; letter-spacing: 1px; }
.peca-dados b { font-size: 14px; margin-right: 8px; font-family: ui-monospace, "Consolas", monospace; }
.peca-dados.em-linhas { display: grid; grid-template-columns: max-content 1fr; gap: 6px 14px; align-items: baseline; margin: 4px 0 8px; }
.peca-dados.em-linhas b { font-size: 16px; margin: 0; }
.cad-form { margin-top: 12px; display: flex; flex-direction: column; gap: 10px; }
.cad-mais summary { cursor: pointer; }
.cad-mais .form-linha { margin-top: 10px; }

/* ---------- Rastrear / ficha ---------- */
.msg { margin-top: 10px; color: var(--accent); font-size: 13px; }
.msg-ok { color: var(--c-inst); font-size: 13px; }
.msg-erro { color: var(--c-canc); font-size: 13px; }
.peca-cab { display: flex; gap: 14px; align-items: center; margin-bottom: 14px; }
.peca-img { width: 64px; height: 64px; flex: 0 0 64px; border-radius: 8px; background: #fff; border: 1px solid var(--linha); display: flex; align-items: center; justify-content: center; overflow: hidden; }
.peca-img img { width: 100%; height: 100%; object-fit: contain; }
.peca-img.sem-img { background: #0c1018; }
.peca-img.sem-img img { display: none; }
.peca-img.sem-img::after { content: "📦"; font-size: 24px; }
.peca-cab-info { flex: 1; min-width: 0; }
.peca-cab-info .item-tipo code { font-size: 12px; }
.trilha { display: flex; align-items: center; gap: 6px; margin-top: 8px; flex-wrap: wrap; }
.trilha-item { font-size: 11px; font-weight: 700; letter-spacing: .3px; color: var(--muted); padding: 2px 8px; border-radius: 20px; border: 1px solid var(--linha); white-space: nowrap; }
.trilha-item.feita { color: #fff; background: var(--cor); border-color: var(--cor); }
.trilha-seta { color: var(--muted); }

.abas-sub { display: flex; gap: 6px; border-bottom: 1px solid var(--linha); margin-bottom: 14px; }
.aba-sub { background: none; border: none; color: var(--muted); cursor: pointer; padding: 8px 14px; font-size: 13px; border-bottom: 2px solid transparent; margin-bottom: -1px; }
.aba-sub.ativa { color: var(--accent); border-bottom-color: var(--accent); }
.aba-sub:hover { color: var(--texto); }

.tracking-form { display: flex; flex-direction: column; gap: 10px; }
.etapa-bloco { border: 1px solid var(--linha); border-radius: 10px; padding: 12px; }
.etapa-bloco h4 { margin: 0 0 8px; font-size: 13px; }

.ver-dados .dados-grade, .dados-grade { display: grid; grid-template-columns: 1fr 1fr; gap: 8px 18px; }
.dado { display: flex; justify-content: space-between; gap: 10px; border-bottom: 1px dotted var(--linha); padding-bottom: 5px; }
.dado span { color: var(--muted); font-size: 13px; }
.dado b { font-size: 13px; text-align: right; word-break: break-all; }
.ver-dados .sub { font-size: 13px; color: var(--muted); text-transform: uppercase; letter-spacing: 1px; margin: 18px 0 8px; }
.hist { display: flex; flex-direction: column; gap: 6px; }
.hist-item { font-size: 13px; }
.hist-item span { font-weight: 700; font-size: 11px; padding: 2px 7px; border-radius: 20px; margin-right: 6px; }
.hist-linha { display: flex; flex-wrap: wrap; align-items: baseline; gap: 4px 8px; border-bottom: 1px dotted var(--linha); padding-bottom: 6px; }
.hist-linha .hist-quando, .hist-linha .hist-quem, .hist-linha .hist-onde, .hist-linha .hist-detalhe { font-weight: 400; font-size: 12px; padding: 0; margin: 0; border-radius: 0; }
.hist-linha .hist-quando { color: var(--texto); }
.hist-linha .hist-quem { color: var(--texto); font-weight: 600; }
.hist-linha .hist-onde { color: var(--muted); }
.hist-linha .hist-detalhe { color: var(--muted); flex-basis: 100%; }
.status-placa_ok { background: rgba(34,197,94,.16); color: var(--c-inst); }
.status-placa_falha { background: rgba(248,113,113,.16); color: var(--c-canc); }

.qr-box { background: #fff; padding: 12px; border-radius: 8px; display: inline-block; }
.qr-box svg { width: 220px; height: 220px; display: block; }
.qr-url { font-family: ui-monospace, Consolas, monospace; font-size: 12px; word-break: break-all; margin-top: 8px; color: var(--muted); }

/* ---------- Leitor de QR pela câmera ---------- */
.scanner { position: fixed; inset: 0; background: #000; z-index: 1000; display: flex; flex-direction: column; }
.scanner-video { flex: 1; width: 100%; height: 100%; object-fit: cover; }
.scanner-mira { position: absolute; left: 50%; top: 50%; width: min(70vw, 300px); aspect-ratio: 1; transform: translate(-50%, -50%); border: 3px solid rgba(255,255,255,.85); border-radius: 14px; box-shadow: 0 0 0 100vmax rgba(0,0,0,.35); pointer-events: none; }
.scanner-rodape { position: absolute; left: 0; right: 0; bottom: 0; padding: 12px 16px 16px; display: flex; flex-direction: column; gap: 10px; background: linear-gradient(transparent, rgba(0,0,0,.8)); }
.scanner-linha { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.scanner-msg { color: #fff; font-size: 14px; word-break: break-all; }
.scanner-lista { position: absolute; left: 12px; right: 12px; top: 12px; max-height: 26vh; overflow: auto; background: rgba(0,0,0,.6); color: #fff; border-radius: 10px; padding: 8px 12px; font-size: 13px; font-family: ui-monospace, "Consolas", monospace; }
.scanner-lista > div { padding: 3px 0; border-bottom: 1px solid rgba(255,255,255,.12); }
.scanner-lista > div:last-child { border-bottom: none; }
.scanner-lista-titulo { font-family: inherit; font-weight: 700; color: #9be4a8; }

/* ---------- Login / telas centrais ---------- */
.tela-centro { min-height: 78vh; display: flex; align-items: center; justify-content: center; padding: 24px; }
.login { width: 100%; max-width: 360px; display: flex; flex-direction: column; gap: 14px; }
.login-marca { text-align: center; font-weight: 700; margin-bottom: 4px; }
.login-marca span { display: block; color: var(--muted); font-size: 11px; text-transform: uppercase; letter-spacing: 1.5px; font-weight: 400; margin-top: 4px; }
.obra-lista { display: flex; flex-direction: column; gap: 8px; }
.obra-lista button { text-align: left; }
code { background: var(--panel-2); padding: 1px 5px; border-radius: 4px; font-size: 12px; }

@media (max-width: 600px) {
  .abas { gap: 0; }
  .aba { padding: 10px 7px; font-size: 12px; letter-spacing: .2px; }
  .dados-grade, .ver-dados .dados-grade { grid-template-columns: 1fr; }
  .linha-grande { font-size: 22px; }
  .campo-curto { flex: 1; }
}

/* ---------- Tabela (resumo da obra) ---------- */
.tabela { width: 100%; border-collapse: collapse; font-size: 13px; }
.tabela th, .tabela td { padding: 6px 8px; border-bottom: 1px solid var(--linha); text-align: right; white-space: nowrap; }
.tabela th:first-child, .tabela td:first-child { text-align: left; white-space: normal; }
.tabela th { color: var(--muted); font-size: 11px; letter-spacing: .5px; text-transform: uppercase; font-weight: 600; }
.tabela tr.clicavel { cursor: pointer; }
.tabela tr.clicavel:hover td { background: rgba(255,255,255,.03); }
.tabela tfoot td { font-weight: 700; border-bottom: none; }
