:root {
  --bg: #f3f5f8;
  --panel: #ffffff;
  --ink: #0f172a;
  --muted: #64748b;
  --line: #e2e8f0;
  --brand: #0b1f33;
  --accent: #0e7c66;
  --accent-ink: #ffffff;
  --danger: #dc2626;
  --warn: #d97706;
  --ok: #16a34a;
  --off: #64748b;
  --violet: #7c3aed;
  --radius: 10px;
  --shadow: 0 1px 2px rgba(15, 23, 42, .06), 0 8px 24px rgba(15, 23, 42, .08);
  --top: 56px;
  --bottom: 0px;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  color: var(--ink);
  background: var(--bg);
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body { overscroll-behavior: none; -webkit-tap-highlight-color: transparent; }
button, input, select, textarea { font: inherit; color: inherit; }
a { color: var(--accent); }
.hidden { display: none !important; }
.muted { color: var(--muted); }
.small { font-size: 12px; }
.mono { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; }
.num { font-variant-numeric: tabular-nums; }

/* ---------- topo e navegação ---------- */
.app { height: 100%; display: flex; flex-direction: column; }
.topbar {
  height: var(--top); flex: none; display: flex; align-items: center; gap: 20px;
  padding: 0 16px; background: var(--brand); color: #fff; z-index: 1000;
}
.brand { display: flex; align-items: center; gap: 10px; color: #fff; text-decoration: none; font-weight: 700; letter-spacing: .2px; }
.nav { display: flex; gap: 4px; flex: 1; }
.nav a {
  display: flex; align-items: center; gap: 8px; padding: 8px 12px; border-radius: 8px;
  color: #cbd5e1; text-decoration: none; font-size: 14px; position: relative; white-space: nowrap;
}
.nav a svg { width: 18px; height: 18px; flex: none; }
.nav a:hover { color: #fff; background: rgba(255, 255, 255, .06); }
.nav a.active { color: #fff; background: rgba(255, 255, 255, .12); }
.badge {
  min-width: 18px; height: 18px; padding: 0 5px; border-radius: 9px; background: var(--danger); color: #fff;
  font-size: 11px; font-weight: 700; display: inline-flex; align-items: center; justify-content: center;
}
.nav .badge { position: absolute; top: 2px; left: 22px; }
.top-right { display: flex; align-items: center; gap: 14px; margin-left: auto; }
.live { display: flex; align-items: center; gap: 6px; font-size: 12px; color: #94a3b8; }
.live i { width: 8px; height: 8px; border-radius: 50%; background: #64748b; }
.live.on i { background: #22c55e; box-shadow: 0 0 0 3px rgba(34, 197, 94, .25); }
.user-chip { color: #e2e8f0; text-decoration: none; font-size: 14px; padding: 6px 10px; border-radius: 8px; background: rgba(255, 255, 255, .08); }

.view { flex: 1; min-height: 0; position: relative; overflow: auto; }

/* ---------- elementos comuns ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px; height: 38px; padding: 0 14px;
  border-radius: 8px; border: 1px solid var(--line); background: var(--panel); cursor: pointer; font-weight: 500;
  text-decoration: none; color: var(--ink); white-space: nowrap;
}
.btn:hover { border-color: #cbd5e1; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn.danger { background: var(--danger); border-color: var(--danger); color: #fff; }
.btn.ghost { border-color: transparent; background: transparent; }
.btn.sm { height: 30px; padding: 0 10px; font-size: 13px; }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn svg { width: 16px; height: 16px; }

input, select, textarea {
  width: 100%; height: 38px; padding: 0 10px; border: 1px solid var(--line); border-radius: 8px; background: #fff;
}
textarea { height: auto; min-height: 70px; padding: 8px 10px; resize: vertical; }
input:focus, select:focus, textarea:focus { outline: 2px solid rgba(14, 124, 102, .35); border-color: var(--accent); }
label.field { display: flex; flex-direction: column; gap: 5px; font-size: 13px; color: var(--muted); }
label.field > span b { color: var(--danger); font-weight: 600; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.grid3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px; }
.span2 { grid-column: span 2; }
fieldset { border: 1px solid var(--line); border-radius: var(--radius); padding: 12px; margin: 0; }
legend { font-size: 13px; font-weight: 600; padding: 0 6px; }

.page { max-width: 1180px; margin: 0 auto; padding: 22px 18px 40px; }
.page-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 16px; flex-wrap: wrap; }
.page-head h1 { font-size: 22px; margin: 0; }
.card { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); }
.card + .card { margin-top: 16px; }
.card-pad { padding: 16px; }
.card h2 { font-size: 15px; margin: 0 0 12px; }
.toolbar { display: flex; gap: 10px; align-items: flex-end; flex-wrap: wrap; padding: 14px 16px; border-bottom: 1px solid var(--line); }
.toolbar > * { flex: 0 1 auto; }
.toolbar label.field { min-width: 160px; }

table.table { width: 100%; border-collapse: collapse; font-size: 14px; }
.table th { text-align: left; font-weight: 600; color: var(--muted); font-size: 12px; text-transform: uppercase; letter-spacing: .4px; padding: 10px 14px; border-bottom: 1px solid var(--line); background: #f8fafc; }
.table td { padding: 11px 14px; border-bottom: 1px solid var(--line); vertical-align: middle; }
.table tr:last-child td { border-bottom: 0; }
.table tr.click { cursor: pointer; }
.table tr.click:hover td { background: #f8fafc; }
.table-wrap { overflow-x: auto; }
.empty { padding: 36px 16px; text-align: center; color: var(--muted); }

.pill { display: inline-flex; align-items: center; gap: 6px; padding: 3px 9px; border-radius: 999px; font-size: 12px; font-weight: 600; background: #f1f5f9; color: var(--ink); white-space: nowrap; }
.pill i { width: 8px; height: 8px; border-radius: 50%; background: currentColor; }

.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 12px; }
.stat { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px 16px; }
.stat .k { font-size: 12px; color: var(--muted); }
.stat .v { font-size: 24px; font-weight: 700; margin-top: 4px; font-variant-numeric: tabular-nums; }
.stat .v small { font-size: 13px; font-weight: 500; color: var(--muted); }

.notice { padding: 12px 14px; border-radius: var(--radius); background: #ecfdf5; border: 1px solid #a7f3d0; font-size: 14px; }
.notice.warn { background: #fffbeb; border-color: #fde68a; }

/* ---------- mapa ---------- */
.map-layout { position: absolute; inset: 0; display: flex; }
.side { width: 340px; flex: none; background: var(--panel); border-right: 1px solid var(--line); display: flex; flex-direction: column; min-height: 0; z-index: 500; }
.side-head { padding: 12px; border-bottom: 1px solid var(--line); display: flex; flex-direction: column; gap: 10px; }
.chips { display: flex; gap: 6px; overflow-x: auto; scrollbar-width: none; }
.chip { flex: none; height: 28px; padding: 0 10px; border-radius: 14px; border: 1px solid var(--line); background: #fff; font-size: 12px; cursor: pointer; display: inline-flex; align-items: center; gap: 5px; }
.chip.active { background: var(--brand); color: #fff; border-color: var(--brand); }
.chip b { font-weight: 700; }
.vlist { flex: 1; overflow-y: auto; }
.vitem { display: flex; gap: 12px; padding: 12px; border-bottom: 1px solid var(--line); cursor: pointer; align-items: center; }
.vitem:hover { background: #f8fafc; }
.vitem.sel { background: #ecfdf5; }
.vdot { width: 36px; height: 36px; border-radius: 50%; flex: none; display: grid; place-items: center; color: #fff; }
.vdot svg { width: 18px; height: 18px; }
.vinfo { flex: 1; min-width: 0; }
.vname { font-weight: 600; font-size: 14px; display: flex; justify-content: space-between; gap: 6px; }
.vname span:first-child { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.vmeta { font-size: 12px; color: var(--muted); margin-top: 3px; display: flex; justify-content: space-between; gap: 6px; }
.map-wrap { flex: 1; position: relative; min-width: 0; }
.map { position: absolute; inset: 0; background: #e5e7eb; }
.leaflet-container { font: inherit; }

.vmarker { position: relative; }
.vmarker .arrow { width: 34px; height: 34px; border-radius: 50%; display: grid; place-items: center; box-shadow: 0 2px 6px rgba(0, 0, 0, .35); border: 2px solid #fff; }
.vmarker .arrow svg { width: 18px; height: 18px; color: #fff; }
.vmarker .tag { position: absolute; top: 37px; left: 50%; transform: translateX(-50%); background: rgba(15, 23, 42, .85); color: #fff; font-size: 11px; font-weight: 600; padding: 2px 6px; border-radius: 4px; white-space: nowrap; }

.detail {
  position: absolute; left: 16px; bottom: 16px; width: 380px; max-height: calc(100% - 32px); overflow-y: auto;
  background: var(--panel); border-radius: 14px; box-shadow: var(--shadow); z-index: 600;
}
.detail-head { padding: 14px 16px 10px; display: flex; justify-content: space-between; gap: 10px; align-items: flex-start; border-bottom: 1px solid var(--line); }
.detail-head h3 { margin: 0; font-size: 17px; }
.detail-body { padding: 12px 16px; }
.kv { display: grid; grid-template-columns: 1fr 1fr; gap: 10px 14px; }
.kv div span { display: block; font-size: 11px; color: var(--muted); text-transform: uppercase; letter-spacing: .3px; }
.kv div b { font-size: 14px; font-weight: 600; }
.speed-big { font-size: 30px; font-weight: 800; font-variant-numeric: tabular-nums; }
.speed-big small { font-size: 13px; color: var(--muted); font-weight: 500; }
.actions { display: flex; flex-wrap: wrap; gap: 8px; padding: 12px 16px 16px; border-top: 1px solid var(--line); }
.addr { font-size: 13px; margin-top: 10px; padding: 8px 10px; background: #f8fafc; border-radius: 8px; }
.cmdlog { margin-top: 10px; font-size: 12px; }
.cmdlog div { display: flex; justify-content: space-between; gap: 8px; padding: 5px 0; border-top: 1px dashed var(--line); }

.fab { position: absolute; z-index: 550; }
.list-toggle { display: none; top: 12px; left: 12px; }

/* histórico */
.hist-layout { position: absolute; inset: 0; display: flex; flex-direction: column; }
.hist-bar { background: var(--panel); border-bottom: 1px solid var(--line); z-index: 500; }
.hist-map { flex: 1; position: relative; }
.player {
  position: absolute; left: 50%; bottom: 18px; transform: translateX(-50%); width: min(640px, calc(100% - 24px));
  background: var(--panel); border-radius: 14px; box-shadow: var(--shadow); z-index: 600; padding: 12px 14px;
}
.player-row { display: flex; align-items: center; gap: 10px; }
.player input[type=range] { flex: 1; height: auto; padding: 0; border: 0; accent-color: var(--accent); }
.player-info { display: flex; justify-content: space-between; gap: 8px; font-size: 13px; margin-top: 8px; flex-wrap: wrap; }
.hist-summary { display: flex; gap: 18px; font-size: 13px; padding: 0 16px 12px; flex-wrap: wrap; }
.hist-summary b { font-size: 15px; }

/* cercas */
.fence-layout { position: absolute; inset: 0; display: flex; }
.fence-form { padding: 14px; border-bottom: 1px solid var(--line); display: flex; flex-direction: column; gap: 10px; }

/* modal */
.modal { position: fixed; inset: 0; background: rgba(15, 23, 42, .5); z-index: 3000; display: flex; align-items: center; justify-content: center; padding: 16px; }
.modal-box { background: var(--panel); border-radius: 14px; width: min(720px, 100%); max-height: calc(100% - 20px); display: flex; flex-direction: column; box-shadow: var(--shadow); }
.modal-box.narrow { width: min(440px, 100%); }
.modal-head { padding: 16px 18px; border-bottom: 1px solid var(--line); display: flex; justify-content: space-between; align-items: center; }
.modal-head h2 { margin: 0; font-size: 17px; }
.modal-body { padding: 18px; overflow-y: auto; display: flex; flex-direction: column; gap: 14px; }
.modal-foot { padding: 14px 18px; border-top: 1px solid var(--line); display: flex; justify-content: flex-end; gap: 8px; }
.form-error { color: var(--danger); font-size: 13px; }

/* toasts */
.toasts { position: fixed; right: 16px; top: calc(var(--top) + 12px); z-index: 4000; display: flex; flex-direction: column; gap: 8px; width: min(360px, calc(100% - 32px)); }
.toast { background: var(--brand); color: #fff; padding: 12px 14px; border-radius: 10px; box-shadow: var(--shadow); font-size: 14px; border-left: 4px solid var(--accent); cursor: pointer; animation: tin .2s ease-out; }
.toast.alert { border-left-color: var(--danger); }
.toast small { display: block; color: #94a3b8; margin-top: 2px; }
@keyframes tin { from { transform: translateY(-6px); opacity: 0; } }

/* login */
.auth { min-height: 100%; display: grid; place-items: center; padding: 20px; background: var(--brand); background-image: linear-gradient(160deg, rgba(255,255,255,.0), rgba(255,255,255,.12)); }
.auth-box { width: min(380px, 100%); background: #fff; border-radius: 16px; padding: 28px; box-shadow: var(--shadow); display: flex; flex-direction: column; gap: 14px; }
.auth-box h1 { margin: 0; font-size: 22px; display: flex; align-items: center; gap: 10px; }
.auth-box p { margin: 0; color: var(--muted); font-size: 14px; }

/* ---------- celular ---------- */
@media (max-width: 860px) {
  :root { --top: 52px; --bottom: calc(60px + env(safe-area-inset-bottom)); }
  .topbar { padding: 0 12px; padding-top: env(safe-area-inset-top); height: calc(var(--top) + env(safe-area-inset-top)); }
  .nav {
    position: fixed; left: 0; right: 0; bottom: 0; height: var(--bottom); padding-bottom: env(safe-area-inset-bottom);
    background: var(--brand); justify-content: space-around; gap: 0; z-index: 2000; border-top: 1px solid rgba(255, 255, 255, .08);
  }
  .nav a { flex-direction: column; gap: 3px; font-size: 10px; padding: 8px 4px; flex: 1; justify-content: center; }
  .nav a.desk { display: none; }
  .nav a.active { background: transparent; color: #5eead4; }
  .nav .badge { left: calc(50% + 4px); top: 4px; }
  .live span { display: none; }
  .view { margin-bottom: var(--bottom); }
  .side { position: absolute; inset: 0; width: 100%; transform: translateX(-100%); transition: transform .2s; }
  .side.open { transform: none; }
  .list-toggle { display: inline-flex; }
  .detail { left: 8px; right: 8px; bottom: 8px; width: auto; max-height: 62%; }
  .grid2, .grid3 { grid-template-columns: 1fr; }
  .span2 { grid-column: auto; }
  .page { padding: 16px 12px 30px; }
  .fence-layout { flex-direction: column; }
  .fence-layout .side { position: relative; transform: none; width: 100%; height: 45%; border-right: 0; border-bottom: 1px solid var(--line); }
  .player { bottom: 10px; }
  .toolbar label.field { min-width: 0; flex: 1 1 140px; }
  .hide-m { display: none; }
}
@media (min-width: 861px) {
  .nav a.mob { display: none; }
  .app { overflow: hidden; }
  .nav { min-width: 0; overflow-x: auto; scrollbar-width: none; }
  .brand { flex: none; white-space: nowrap; }
}
/* telas médias: menu só com ícones */
@media (min-width: 861px) and (max-width: 1240px) {
  .nav a > span:not(.badge) { display: none; }
  .nav a { padding: 8px 10px; }
  .live span { display: none; }
}

/* ---------- app do cliente: rastreados e ficha ---------- */
.tpage { max-width: 760px; margin: 0 auto; background: var(--panel); min-height: 100%; }
.tsearch { padding: 12px 14px 4px; position: sticky; top: 0; background: var(--panel); z-index: 5; }
.ttabs { display: grid; grid-template-columns: 1fr 1fr; border-bottom: 1px solid var(--line); position: sticky; top: 54px; background: var(--panel); z-index: 5; }
.ttabs button { background: none; border: 0; padding: 13px 0; font-size: 16px; font-weight: 600; color: var(--muted); border-bottom: 3px solid transparent; cursor: pointer; }
.ttabs button.on { color: var(--accent); border-bottom-color: var(--accent); }
.tcard { display: flex; gap: 12px; padding: 16px 16px 14px; border-bottom: 1px solid var(--line); cursor: pointer; }
.tcard:active { background: #f8fafc; }
.tmain { flex: 1; min-width: 0; }
.ttitle { font-size: 17px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.ttitle b { font-weight: 700; }
.ttitle span { color: var(--muted); font-weight: 500; margin-left: 4px; }
.ttitle.center { flex: 1; text-align: center; }
.taddr { color: var(--muted); font-size: 14px; margin-top: 4px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.tchips { display: flex; gap: 6px; flex-wrap: wrap; margin-top: 9px; }
.tchip { display: inline-flex; align-items: center; gap: 5px; font-size: 13px; font-weight: 600; padding: 3px 9px; border-radius: 6px; background: #f1f5f9; color: var(--ink); white-space: nowrap; }
.tchip svg { width: 15px; height: 15px; }
.tchip.bad { color: var(--danger); background: #fef2f2; }
.tfoot { display: flex; justify-content: space-between; gap: 8px; margin-top: 12px; font-size: 13px; color: var(--muted); }
.tfoot span:first-child { display: flex; align-items: center; gap: 6px; color: var(--ink); min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tfoot svg { width: 17px; height: 17px; flex: none; color: var(--muted); }
.tside { display: flex; flex-direction: column; align-items: flex-end; gap: 8px; flex: none; }
.tstar { background: none; border: 0; padding: 0; width: 28px; height: 28px; cursor: pointer; color: #cbd5e1; }
.tstar svg, .ticon svg { width: 100%; height: 100%; }
.tthumb { width: 86px; height: 86px; border-radius: 10px; background: #f1f5f9; display: grid; place-items: center; color: #64748b; overflow: hidden; flex: none; }
.tthumb img { width: 100%; height: 100%; object-fit: cover; }
.tthumb svg { width: 34px; height: 34px; }

.thead { display: flex; align-items: center; gap: 10px; padding: 10px 12px; border-bottom: 1px solid var(--line); position: sticky; top: 0; background: var(--panel); z-index: 5; }
.ticon { width: 34px; height: 34px; padding: 5px; background: none; border: 0; color: var(--ink); cursor: pointer; display: inline-flex; flex: none; }
#dStar { color: #cbd5e1; }
.tsec { padding: 14px 16px; }
.trow { display: flex; align-items: center; gap: 10px; margin-top: 10px; font-size: 15px; }
.trow svg { width: 20px; height: 20px; color: var(--muted); flex: none; }
.tstats { display: grid; grid-template-columns: 1fr 1fr; border-top: 1px solid var(--line); border-bottom: 1px solid var(--line); margin: 4px 0 14px; }
.tstats div { text-align: center; padding: 16px 0; }
.tstats b { display: block; font-size: 22px; font-variant-numeric: tabular-nums; }
.tstats span { color: var(--muted); font-size: 14px; }
.tminimap { height: 160px; border-radius: 12px; overflow: hidden; border: 1px solid var(--line); cursor: pointer; }
.tmenu { display: flex; flex-direction: column; padding: 4px 0 24px; }
.tmenu > a, .tmenu > button { display: flex; align-items: center; gap: 16px; padding: 16px 18px; background: none; border: 0; text-align: left; font-size: 16px; color: var(--ink); text-decoration: none; cursor: pointer; }
.tmenu > a:active, .tmenu > button:active { background: #f8fafc; }
.tmenu span { flex: 1; }
.tmenu svg { width: 22px; height: 22px; color: #475569; flex: none; }
.tmenu svg:last-child { width: 18px; height: 18px; color: #94a3b8; }
@media (min-width: 861px) {
  .tpage { margin: 18px auto; border: 1px solid var(--line); border-radius: 14px; min-height: auto; overflow: hidden; }
  .tsearch, .ttabs, .thead { position: static; }
}
.tfoot span:last-child { white-space: nowrap; flex: none; }
