:root {
  --bg: #f3f5f8;
  --card: #ffffff;
  --text: #1b2430;
  --muted: #5f6b7a;
  --line: #dde3ea;
  --primary: #0f3d5e;
  --primary-2: #175a89;
  --ok: #1f8a4c;
  --ok-bg: #e5f5ec;
  --warn: #a96200;
  --warn-bg: #fff3dc;
  --danger: #c0392b;
  --danger-bg: #fdecea;
  --info-bg: #e6f0f8;
  --radius: 12px;
  --shadow: 0 1px 3px rgba(16, 24, 40, .08), 0 1px 2px rgba(16, 24, 40, .04);
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  color-scheme: light;
}

* { box-sizing: border-box; }
html, body { margin: 0; background: var(--bg); color: var(--text); font-size: 16px; }
body { padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left); }
button, input, select, textarea { font: inherit; color: inherit; }
[hidden] { display: none !important; }

#offline {
  position: sticky; top: 0; z-index: 50;
  background: var(--danger); color: #fff; text-align: center; padding: 8px; font-weight: 600;
}

/* ---------- Layout ---------- */
.topbar {
  display: flex; align-items: center; gap: 12px; flex-wrap: wrap;
  background: var(--primary); color: #fff; padding: 10px 16px;
}
.topbar .marca { font-weight: 700; font-size: 1.15rem; margin-right: auto; display: flex; align-items: center; gap: 8px; }
.topbar .marca img { width: 28px; height: 28px; border-radius: 6px; }
.topbar .quem { font-size: .9rem; opacity: .9; text-align: right; line-height: 1.2; }
.topbar .quem small { display: block; opacity: .8; }
.topbar .btn-sair { background: transparent; border: 1px solid rgba(255,255,255,.4); color: #fff; padding: 6px 12px; border-radius: 8px; cursor: pointer; }

.abas {
  display: flex; gap: 4px; overflow-x: auto; background: var(--card);
  border-bottom: 1px solid var(--line); padding: 0 12px; position: sticky; top: 0; z-index: 10;
}
.abas button {
  border: 0; background: none; padding: 14px 16px; cursor: pointer; white-space: nowrap;
  border-bottom: 3px solid transparent; color: var(--muted); font-weight: 600; position: relative;
}
.abas button.ativa { color: var(--primary); border-bottom-color: var(--primary); }
.abas .badge { margin-left: 6px; }

main { padding: 16px; max-width: 1280px; margin: 0 auto; }
.cabecalho { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; margin-bottom: 14px; }
.cabecalho h2 { margin: 0; font-size: 1.3rem; margin-right: auto; }

.cards-resumo { display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); gap: 12px; margin-bottom: 16px; }
.resumo { background: var(--card); border-radius: var(--radius); padding: 14px 16px; box-shadow: var(--shadow); }
.resumo .num { font-size: 2rem; font-weight: 700; color: var(--primary); }
.resumo .rot { color: var(--muted); font-size: .9rem; }

.grade { display: grid; grid-template-columns: repeat(auto-fill, minmax(290px, 1fr)); gap: 12px; }
.card {
  background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow);
  padding: 14px 16px; display: flex; flex-direction: column; gap: 6px; border-left: 5px solid var(--primary-2);
}
.card.esperado { border-left-color: var(--warn); }
.card.chegou { border-left-color: var(--ok); }
.card.cancelado, .card.concluido { border-left-color: var(--line); opacity: .75; }
.card .linha1 { display: flex; align-items: center; gap: 10px; justify-content: space-between; }
.card .titulo { font-weight: 700; font-size: 1.1rem; }
.card .det { color: var(--muted); font-size: .92rem; }
.card .acoes { display: flex; gap: 8px; margin-top: 6px; flex-wrap: wrap; }

.placa {
  display: inline-block; font-family: "Courier New", monospace; font-weight: 700; letter-spacing: 1px;
  background: #fff; border: 2px solid #1b2430; border-top: 6px solid #1d4fa3; border-radius: 6px;
  padding: 2px 8px; font-size: 1.05rem;
}

.badge { display: inline-block; padding: 2px 8px; border-radius: 999px; font-size: .78rem; font-weight: 700; background: var(--info-bg); color: var(--primary); }
.badge.ok { background: var(--ok-bg); color: var(--ok); }
.badge.warn { background: var(--warn-bg); color: var(--warn); }
.badge.danger { background: var(--danger-bg); color: var(--danger); }
.badge.cinza { background: #eef0f3; color: var(--muted); }
.ramal { display: inline-block; font-weight: 800; font-size: 1.1rem; color: var(--ok); background: var(--ok-bg); padding: 2px 10px; border-radius: 8px; white-space: nowrap; }
.ramal.peq { font-size: .95rem; padding: 1px 8px; }
/* Busca rápida no formulário de entrada */
.busca-rapida { margin-bottom: 12px; position: relative; }
.busca-rapida input { width: 100%; min-height: 52px; border: 2px solid var(--primary-2); border-radius: 12px; padding: 0 14px; font-size: 1.05rem; background: #fff; }
.sugestoes { display: flex; flex-direction: column; gap: 6px; margin-top: 6px; max-height: 300px; overflow-y: auto; }
.sugestao { display: flex; justify-content: space-between; align-items: center; gap: 10px; text-align: left; border: 1px solid var(--line); background: #fff; border-radius: 10px; padding: 10px 12px; cursor: pointer; min-height: 52px; }
.sugestao:hover, .sugestao:focus { border-color: var(--primary-2); background: var(--info-bg); }
.sugestao small { display: block; }
.chips-setor .setor-chip { min-height: 52px; padding: 10px 18px; font-size: 1rem; }
.mais-detalhes { border: 1px dashed var(--line); border-radius: 10px; padding: 10px 12px; }
.mais-detalhes summary { cursor: pointer; font-weight: 600; color: var(--primary); min-height: 32px; display: flex; align-items: center; gap: 6px; }

/* Leitor de QR */
.leitor { position: relative; background: #000; border-radius: 12px; overflow: hidden; aspect-ratio: 4 / 3; max-width: 100%; }
.leitor video { width: 100%; height: 100%; object-fit: cover; display: block; }
.leitor .mira { position: absolute; inset: 18%; border: 3px solid rgba(255,255,255,.85); border-radius: 14px; box-shadow: 0 0 0 999px rgba(0,0,0,.25); }
.acoes-convite { display: flex; flex-direction: column; gap: 10px; margin-top: 12px; }
.acoes-convite .btn { text-decoration: none; color: inherit; }
.acoes-convite .btn.ok { color: #fff; }

.badge.a-pe { background: #f1ecfb; color: #5b3b9a; font-size: .95rem; padding: 4px 10px; }
.chip.grande-chip { min-height: 52px; padding: 10px 20px; font-size: 1.05rem; flex: 1; max-width: 240px; }

.vazio { text-align: center; color: var(--muted); padding: 40px 16px; background: var(--card); border-radius: var(--radius); }

/* ---------- Botões / formulários ---------- */
.btn {
  border: 1px solid var(--line); background: var(--card); padding: 10px 16px; border-radius: 10px;
  cursor: pointer; font-weight: 600; min-height: 44px; display: inline-flex; align-items: center; justify-content: center; gap: 6px;
}
.btn:disabled { opacity: .55; cursor: default; }
.btn.prim { background: var(--primary); border-color: var(--primary); color: #fff; }
.btn.ok { background: var(--ok); border-color: var(--ok); color: #fff; }
.btn.perigo { background: var(--danger); border-color: var(--danger); color: #fff; }
.btn.grande { min-height: 56px; font-size: 1.1rem; padding: 12px 22px; }
.btn.peq { min-height: 34px; padding: 6px 10px; font-size: .9rem; }

.form { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 12px 14px; }
.form .full { grid-column: 1 / -1; }
.campo { display: flex; flex-direction: column; gap: 4px; }
.campo label { font-size: .85rem; font-weight: 600; color: var(--muted); }
.campo input, .campo select, .campo textarea {
  border: 1px solid var(--line); border-radius: 10px; padding: 10px 12px; min-height: 46px; background: #fff; width: 100%;
}
.campo input:focus, .campo select:focus, .campo textarea:focus { outline: 2px solid var(--primary-2); border-color: var(--primary-2); }
.campo input.placa-input { text-transform: uppercase; font-family: "Courier New", monospace; font-weight: 700; font-size: 1.3rem; letter-spacing: 2px; }
.campo .dica { font-size: .82rem; color: var(--muted); }
.check { display: flex; align-items: center; gap: 8px; min-height: 46px; }
.check input { width: 22px; height: 22px; }

.filtros { display: flex; gap: 10px; flex-wrap: wrap; align-items: flex-end; background: var(--card); padding: 12px; border-radius: var(--radius); box-shadow: var(--shadow); margin-bottom: 14px; }
.filtros .campo { min-width: 140px; flex: 1; }

.chips { display: flex; gap: 8px; flex-wrap: wrap; }
.chip { border: 1px solid var(--line); background: #fff; border-radius: 999px; padding: 8px 14px; cursor: pointer; font-weight: 600; min-height: 40px; }
.chip.sel { background: var(--primary); color: #fff; border-color: var(--primary); }

/* ---------- Tabela ---------- */
.tabela-wrap { overflow-x: auto; background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow); }
table { width: 100%; border-collapse: collapse; font-size: .93rem; }
th, td { padding: 10px 12px; text-align: left; border-bottom: 1px solid var(--line); white-space: nowrap; }
th { background: #f8fafc; color: var(--muted); font-size: .8rem; text-transform: uppercase; letter-spacing: .3px; }
td.quebra { white-space: normal; min-width: 180px; }

/* ---------- Avisos ---------- */
.avisos { display: flex; flex-direction: column; gap: 10px; }
.aviso { background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow); padding: 12px 16px; border-left: 5px solid var(--primary-2); }
.aviso.urgente { border-left-color: var(--danger); background: #fffafa; }
.aviso .meta { color: var(--muted); font-size: .85rem; display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.aviso .texto { margin: 6px 0; white-space: pre-wrap; font-size: 1.02rem; }
.novo-aviso { background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow); padding: 12px; margin-bottom: 14px; display: flex; flex-direction: column; gap: 8px; }
.novo-aviso textarea { border: 1px solid var(--line); border-radius: 10px; padding: 10px; min-height: 70px; resize: vertical; }
.novo-aviso .rodape { display: flex; justify-content: space-between; align-items: center; gap: 8px; flex-wrap: wrap; }

/* ---------- Login ---------- */
.login-wrap { min-height: 100vh; display: grid; place-items: center; padding: 16px; background: linear-gradient(160deg, var(--primary), #0b2a40); }
.login { background: var(--card); padding: 28px; border-radius: 16px; width: min(400px, 100%); display: flex; flex-direction: column; gap: 14px; box-shadow: 0 10px 40px rgba(0,0,0,.25); }
.login h1 { margin: 0; font-size: 1.5rem; display: flex; align-items: center; gap: 10px; }
.login h1 img { width: 40px; height: 40px; border-radius: 8px; }
.erro { color: var(--danger); font-weight: 600; min-height: 1.2em; }

/* ---------- Modal ---------- */
.modal-fundo { position: fixed; inset: 0; background: rgba(15, 23, 42, .5); display: flex; align-items: flex-start; justify-content: center; padding: 24px 12px; overflow-y: auto; z-index: 40; }
.modal { background: var(--card); border-radius: 16px; width: min(760px, 100%); padding: 20px; box-shadow: 0 20px 50px rgba(0,0,0,.3); }
.modal h3 { margin: 0 0 14px; font-size: 1.25rem; }
.modal .rodape { display: flex; justify-content: flex-end; gap: 10px; margin-top: 18px; flex-wrap: wrap; }
.alerta { padding: 10px 12px; border-radius: 10px; background: var(--warn-bg); color: var(--warn); font-weight: 600; margin-bottom: 12px; }
.alerta.info { background: var(--info-bg); color: var(--primary); }

/* ---------- Toasts ---------- */
#toasts { position: fixed; right: 16px; bottom: 16px; display: flex; flex-direction: column; gap: 8px; z-index: 60; max-width: min(420px, calc(100vw - 32px)); }
.toast { background: #1b2430; color: #fff; padding: 12px 16px; border-radius: 10px; box-shadow: 0 6px 20px rgba(0,0,0,.25); animation: entra .2s ease-out; }
.toast.ok { background: var(--ok); }
.toast.erro { background: var(--danger); }
.toast.alerta { background: var(--warn); }
@keyframes entra { from { transform: translateY(10px); opacity: 0; } }

@media (max-width: 600px) {
  main { padding: 12px; }
  .topbar .quem small { display: none; }
}
