:root {
  --navy: #0b2545;
  --navy-2: #13315c;
  --blue: #1d6fe0;
  --yellow: #f5b700;
  --bg: #f3f5f9;
  --surface: #ffffff;
  --text: #16202e;
  --muted: #667085;
  --line: #e3e7ee;
  --movimento: #16a34a;
  --ligado: #f59e0b;
  --desligado: #3b82f6;
  --offline: #9aa3b2;
  --danger: #dc2626;
  --radius: 10px;
  --shadow: 0 8px 28px rgba(11, 37, 69, .16);
  font-family: "Segoe UI", system-ui, -apple-system, Roboto, sans-serif;
  color: var(--text);
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; background: var(--bg); }
button { font: inherit; cursor: pointer; }
input, select { font: inherit; }
[hidden] { display: none !important; }
.muted { color: var(--muted); font-size: 13px; }

/* ---------- botões ---------- */
.btn { border: 1px solid var(--line); background: var(--surface); color: var(--text);
  padding: 7px 12px; border-radius: 8px; font-size: 13px; font-weight: 600; }
.btn:hover { border-color: var(--blue); color: var(--blue); }
.btn.primary { background: var(--blue); border-color: var(--blue); color: #fff; }
.btn.primary:hover { background: #155bc0; color: #fff; }
.btn.ghost { background: transparent; border-color: transparent; color: inherit; }
.btn.ghost:hover { background: rgba(255,255,255,.1); color: inherit; }
.btn.small { padding: 4px 9px; font-size: 12px; }
.btn.full { width: 100%; padding: 10px; }
.btn.danger { color: var(--danger); }
.btn:disabled { opacity: .45; cursor: not-allowed; pointer-events: none; }
.icon-btn { border: 0; background: transparent; font-size: 16px; color: var(--muted); padding: 4px 8px; border-radius: 6px; }
.icon-btn:hover { background: var(--bg); color: var(--text); }

/* ---------- topo ---------- */
.topbar { height: 60px; background: var(--navy); color: #fff; display: flex; align-items: center;
  gap: 18px; padding: 0 16px; position: relative; z-index: 1000; }
.brand { display: flex; align-items: center; gap: 10px; font-size: 18px; white-space: nowrap; }
.brand img { height: 38px; background: #fff; border-radius: 8px; padding: 2px; }
.brand b { color: var(--yellow); }
.kpis { display: flex; gap: 6px; flex: 1; overflow-x: auto; scrollbar-width: none; }
.kpi { display: flex; align-items: center; gap: 6px; padding: 6px 12px; border-radius: 8px;
  background: var(--navy-2); white-space: nowrap; }
.kpi b { font-size: 17px; }
.kpi small { color: #b8c4d6; font-size: 12px; }
.kpi.alarm { background: transparent; border: 1px solid #2c4a75; cursor: pointer; }
.kpi.alarm.on { background: var(--danger); border-color: var(--danger); animation: pulse 1.6s infinite; }
.kpi.alarm.on small { color: #fff; }
@keyframes pulse { 50% { box-shadow: 0 0 0 6px rgba(220,38,38,.25); } }
.user { display: flex; align-items: center; gap: 4px; white-space: nowrap; font-size: 13px; }
.conn { color: var(--offline); font-size: 12px; margin-right: 6px; }
.conn.on { color: #4ade80; }
.dot { width: 10px; height: 10px; border-radius: 50%; display: inline-block; flex: none; }
.dot.movimento { background: var(--movimento); } .dot.ligado { background: var(--ligado); }
.dot.desligado { background: var(--desligado); } .dot.offline { background: var(--offline); }

/* ---------- layout ---------- */
.layout { display: flex; height: calc(100% - 60px); }
.side { width: 340px; background: var(--surface); border-right: 1px solid var(--line);
  display: flex; flex-direction: column; min-height: 0; }
.map-wrap { flex: 1; position: relative; min-width: 0; }
#map { position: absolute; inset: 0; }

.tabs { display: flex; border-bottom: 1px solid var(--line); }
.tab { flex: 1; border: 0; background: none; padding: 12px; font-weight: 600; color: var(--muted);
  border-bottom: 2px solid transparent; }
.tab.active { color: var(--blue); border-bottom-color: var(--blue); }
.badge { background: var(--danger); color: #fff; border-radius: 10px; padding: 1px 7px; font-size: 11px; }
.badge:empty, .badge.zero { display: none; }
.pane { display: flex; flex-direction: column; min-height: 0; flex: 1; }
.search { margin: 12px 12px 8px; padding: 9px 12px; border: 1px solid var(--line); border-radius: 8px; }
.chips { display: flex; gap: 6px; padding: 0 12px 10px; flex-wrap: wrap; }
.chip { border: 1px solid var(--line); background: var(--surface); border-radius: 20px; padding: 4px 10px;
  font-size: 12px; color: var(--muted); }
.chip.active, .chip:hover { border-color: var(--blue); color: var(--blue); background: #eef4ff; }
.list { list-style: none; margin: 0; padding: 0; overflow-y: auto; flex: 1; }
.list li { padding: 10px 14px; border-top: 1px solid var(--line); cursor: pointer; display: flex; gap: 10px;
  align-items: center; }
.list li:hover { background: #f7f9fc; }
.list li.sel { background: #eef4ff; box-shadow: inset 3px 0 var(--blue); }
.list .info { flex: 1; min-width: 0; }
.list .t { font-weight: 600; font-size: 14px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.list .s { font-size: 12px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.list .v { font-weight: 700; font-size: 13px; text-align: right; white-space: nowrap; }
.list .v small { display: block; font-weight: 400; color: var(--muted); font-size: 11px; }
.list li.alarme .lvl { width: 4px; align-self: stretch; border-radius: 2px; background: var(--ligado); }
.list li.alarme .lvl.n2 { background: var(--danger); }
.list li.alarme.tratado { opacity: .55; }
.tag { font-size: 10px; font-weight: 700; padding: 1px 6px; border-radius: 4px; background: var(--bg); color: var(--muted); margin-right: 4px; }
.tag.DSM { background: #fde8e8; color: #b42318; } .tag.ADAS { background: #fff3d6; color: #9a6400; }
.tag.GPS { background: #e6efff; color: #1d4ed8; } .tag.VIDEO { background: #efe8ff; color: #6d28d9; }
.empty { padding: 24px; text-align: center; color: var(--muted); font-size: 13px; line-height: 1.6; }
.row { display: flex; gap: 8px; align-items: center; }
.row.between { justify-content: space-between; } .row.end { justify-content: flex-end; margin-top: 16px; }
.row.wrap { flex-wrap: wrap; } .pad { padding: 10px 12px; }
.check { font-size: 13px; display: flex; gap: 6px; align-items: center; }

/* ---------- cartões sobre o mapa ---------- */
.card { position: absolute; z-index: 900; background: var(--surface); border-radius: var(--radius);
  box-shadow: var(--shadow); padding: 14px 16px; }
.detail { top: 14px; right: 14px; width: 330px; }
.history { left: 14px; right: 14px; bottom: 14px; max-width: 760px; }
.detail-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 8px; }
.detail h2, .history h2 { margin: 0; font-size: 17px; }
.status-pill { display: inline-flex; align-items: center; gap: 6px; margin: 10px 0; font-size: 12px;
  font-weight: 700; padding: 4px 10px; border-radius: 20px; background: var(--bg); }
.grid { display: grid; grid-template-columns: auto 1fr; gap: 5px 12px; margin: 0 0 12px; font-size: 13px; }
.grid dt { color: var(--muted); } .grid dd { margin: 0; font-weight: 600; text-align: right; }
.actions { display: flex; flex-wrap: wrap; gap: 6px; }
.history label { font-size: 12px; color: var(--muted); display: flex; flex-direction: column; gap: 3px; }
.history input[type=datetime-local] { border: 1px solid var(--line); border-radius: 6px; padding: 5px 7px; }
.history .row.wrap { align-items: flex-end; margin-top: 10px; }
.quick { margin-top: 8px; }
.stats { display: flex; gap: 8px; margin-top: 12px; flex-wrap: wrap; }
.stat { background: var(--bg); border-radius: 8px; padding: 8px 12px; min-width: 110px; }
.stat b { display: block; font-size: 18px; } .stat small { color: var(--muted); font-size: 11px; }
.replay { display: flex; align-items: center; gap: 10px; margin-top: 12px; flex-wrap: wrap; }
.replay input[type=range] { flex: 1; min-width: 160px; accent-color: var(--blue); }
.replay select { border: 1px solid var(--line); border-radius: 6px; padding: 3px; }
.replay-info { font-size: 12px; color: var(--muted); width: 100%; }
.play { background: var(--blue); color: #fff; width: 34px; height: 34px; border-radius: 50%; }
.play:hover { background: #155bc0; color: #fff; }

/* ---------- vídeo ---------- */
.video { left: 58px; top: 14px; width: min(620px, calc(100% - 420px)); min-width: 340px;
  max-height: calc(100% - 28px); overflow: auto; }
.video h2 { margin: 0; font-size: 17px; }
.vbar { margin: 10px 0; align-items: center; justify-content: space-between; gap: 8px; }
.vbar .chips { padding: 0; margin: 0; }
.vbar select { border: 1px solid var(--line); border-radius: 6px; padding: 4px 6px; font-size: 13px; }
.vgrid { display: grid; grid-template-columns: 1fr; gap: 8px; }
.vgrid.multi { grid-template-columns: 1fr 1fr; }
.vtile { position: relative; background: #05101f; border-radius: 8px; overflow: hidden; aspect-ratio: 16 / 9; }
.vtile canvas { width: 100%; height: 100%; object-fit: contain; display: block; }
.vtile .vlbl { position: absolute; left: 8px; top: 6px; color: #fff; font-size: 12px; font-weight: 700;
  background: rgba(11,37,69,.7); padding: 2px 7px; border-radius: 4px; }
.vtile .vrate { position: absolute; right: 8px; top: 6px; color: #cfe0ff; font-size: 11px;
  background: rgba(11,37,69,.7); padding: 2px 7px; border-radius: 4px; }
.vtile .vmsg { position: absolute; inset: 0; display: grid; place-content: center; gap: 10px; text-align: center;
  color: #e6edf7; font-size: 13px; padding: 16px; }
.vtile .vmsg[hidden] { display: none; }
.vtile .vmsg .btn { justify-self: center; }
.vtile .vfull { position: absolute; right: 6px; bottom: 6px; background: rgba(11,37,69,.7); color: #fff; }
.video .hint { font-size: 12px; color: var(--muted); margin: 8px 0 0; }

/* ---------- marcadores ---------- */
.vmark { position: relative; }
.vmark .arrow { width: 30px; height: 30px; border-radius: 50%; border: 3px solid #fff;
  box-shadow: 0 2px 6px rgba(0,0,0,.35); display: grid; place-items: center; }
.vmark .arrow svg { width: 16px; height: 16px; fill: #fff; }
.vmark .lbl { position: absolute; left: 50%; top: 33px; transform: translateX(-50%); background: var(--navy);
  color: #fff; font-size: 11px; font-weight: 600; padding: 1px 6px; border-radius: 4px; white-space: nowrap; }
.vmark.sel .arrow { outline: 3px solid var(--yellow); }
.amark { width: 18px; height: 18px; border-radius: 50%; background: var(--danger); border: 2px solid #fff;
  color: #fff; font-size: 11px; font-weight: 800; display: grid; place-items: center; box-shadow: 0 1px 4px rgba(0,0,0,.4); }
.pmark { width: 14px; height: 14px; border-radius: 50%; border: 3px solid #fff; box-shadow: 0 1px 4px rgba(0,0,0,.4); }

/* ---------- toasts e diálogo ---------- */
.toasts { position: fixed; right: 16px; bottom: 16px; z-index: 3000; display: flex; flex-direction: column; gap: 8px; }
.toast { background: var(--navy); color: #fff; padding: 10px 14px; border-radius: 8px; box-shadow: var(--shadow);
  font-size: 13px; max-width: 340px; border-left: 4px solid var(--yellow); cursor: pointer; animation: in .25s; }
.toast.n2 { border-left-color: var(--danger); }
.toast b { display: block; }
@keyframes in { from { transform: translateY(10px); opacity: 0; } }
.dialog { border: 0; border-radius: 12px; box-shadow: var(--shadow); padding: 20px 22px; width: min(460px, 92vw); }
.dialog::backdrop { background: rgba(11,37,69,.45); }
.dialog h2 { margin: 0 0 14px; font-size: 18px; }
.dialog label, .login-card label { display: flex; flex-direction: column; gap: 4px; font-size: 13px;
  color: var(--muted); margin-bottom: 10px; }
.dialog input, .dialog textarea, .dialog select, .login-card input { border: 1px solid var(--line); border-radius: 8px;
  padding: 9px 11px; font-size: 14px; color: var(--text); }
.dialog .hint { font-size: 12px; color: var(--muted); margin: -4px 0 10px; }
.dialog table { width: 100%; border-collapse: collapse; font-size: 13px; margin-bottom: 12px; }
.dialog td, .dialog th { padding: 6px 4px; border-bottom: 1px solid var(--line); text-align: left; }
.erro { color: var(--danger); font-size: 13px; min-height: 18px; }

/* ---------- login ---------- */
.login-body { display: grid; place-items: center; background: linear-gradient(135deg, var(--navy), #1b3f73); }
.login-card { background: #fff; padding: 32px; border-radius: 14px; width: min(360px, 92vw); box-shadow: var(--shadow); text-align: center; }
.login-card label { text-align: left; }
.login-card h1 { margin: 8px 0 2px; font-size: 22px; }
.login-card p { margin: 0 0 22px; }
.login-logo { height: 72px; }

/* ---------- celular ---------- */
@media (max-width: 820px) {
  .topbar { height: auto; flex-wrap: wrap; padding: 8px 12px; gap: 8px; }
  .kpis { order: 3; width: 100%; flex: none; }
  .user #me { display: none; }
  .layout { flex-direction: column; height: auto; min-height: calc(100% - 110px); }
  .side { width: 100%; height: 42vh; border-right: 0; border-bottom: 1px solid var(--line); }
  .map-wrap { height: 58vh; flex: none; }
  .detail { left: 8px; right: 8px; top: auto; bottom: 8px; width: auto; }
  .history { left: 8px; right: 8px; bottom: 8px; }
  .video { left: 8px; right: 8px; top: 8px; width: auto; min-width: 0; max-height: calc(100% - 16px); }
  .vgrid.multi { grid-template-columns: 1fr; }
}
