/* ==========================================================================
   OlhaZ — design system (sem build: CSS puro com variáveis)
   Tema claro padrão; escuro via [data-theme="dark"] ou preferência do sistema.
   ========================================================================== */

:root {
  --brand: #4f46e5;
  --brand-600: #4338ca;
  --brand-50: #eef2ff;
  --brand-100: #e0e7ff;
  --accent: #06b6d4;

  --bg: #f6f7fb;
  --surface: #ffffff;
  --surface-2: #f9fafb;
  --surface-3: #f1f3f8;
  --border: #e6e8ef;
  --border-strong: #d5d9e3;
  --text: #0f172a;
  --text-2: #475569;
  --text-3: #8a94a6;

  --green: #16a34a;  --green-bg: #dcfce7;
  --amber: #d97706;  --amber-bg: #fef3c7;
  --red: #dc2626;    --red-bg: #fee2e2;
  --blue: #2563eb;   --blue-bg: #dbeafe;
  --gray: #64748b;   --gray-bg: #eef1f5;
  --violet: #7c3aed; --violet-bg: #ede9fe;

  --state-moving: #16a34a;
  --state-idle: #f59e0b;
  --state-stopped: #3b82f6;
  --state-offline: #94a3b8;
  --state-never: #cbd5e1;

  --radius: 12px;
  --radius-sm: 8px;
  --radius-lg: 18px;
  --shadow-sm: 0 1px 2px rgba(15, 23, 42, .06);
  --shadow: 0 1px 3px rgba(15, 23, 42, .06), 0 6px 16px rgba(15, 23, 42, .06);
  --shadow-lg: 0 12px 40px rgba(15, 23, 42, .16);
  --sidebar-w: 248px;
  --topbar-h: 60px;
  --font: 'Inter', system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
  --mono: 'JetBrains Mono', ui-monospace, SFMono-Regular, Menlo, monospace;
  color-scheme: light;
}

[data-theme="dark"] {
  --brand: #818cf8;
  --brand-600: #6366f1;
  --brand-50: #1e1b4b;
  --brand-100: #312e81;
  --bg: #0b0f19;
  --surface: #111827;
  --surface-2: #0f1522;
  --surface-3: #1a2233;
  --border: #1f2937;
  --border-strong: #334155;
  --text: #e5e7eb;
  --text-2: #a3adbf;
  --text-3: #6b7689;
  --green-bg: #052e1a; --amber-bg: #3a2604; --red-bg: #3b0d0d; --blue-bg: #0c1f46; --gray-bg: #1a2233; --violet-bg: #2a1758;
  --shadow: 0 1px 3px rgba(0, 0, 0, .4), 0 6px 16px rgba(0, 0, 0, .3);
  --shadow-lg: 0 16px 48px rgba(0, 0, 0, .5);
  color-scheme: dark;
}

*, *::before, *::after { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0; font-family: var(--font); font-size: 14px; line-height: 1.5;
  color: var(--text); background: var(--bg); -webkit-font-smoothing: antialiased;
}
a { color: var(--brand); text-decoration: none; }
a:hover { text-decoration: underline; }
h1, h2, h3, h4 { margin: 0; font-weight: 650; letter-spacing: -.01em; }
h1 { font-size: 22px; } h2 { font-size: 18px; } h3 { font-size: 15px; } h4 { font-size: 13px; }
p { margin: 0; }
img { max-width: 100%; }
[x-cloak] { display: none !important; }
i[data-lucide] { display: contents; font-style: normal; }
code, pre, .mono { font-family: var(--mono); font-size: 12.5px; }
hr { border: 0; border-top: 1px solid var(--border); margin: 16px 0; }
::selection { background: var(--brand-100); }

/* ---------- Layout ---------- */
.shell { display: flex; min-height: 100vh; }
.sidebar {
  width: var(--sidebar-w); flex-shrink: 0; background: var(--surface); border-right: 1px solid var(--border);
  display: flex; flex-direction: column; position: fixed; inset: 0 auto 0 0; z-index: 1100; transition: transform .2s;
}
.sidebar .brand { display: flex; align-items: center; gap: 10px; padding: 18px 20px; font-weight: 750; font-size: 18px; color: var(--text); }
.sidebar .brand:hover { text-decoration: none; }
.logo-mark {
  width: 32px; height: 32px; border-radius: 10px; display: grid; place-items: center; color: #fff;
  background: linear-gradient(135deg, #4f46e5, #06b6d4); box-shadow: 0 4px 12px rgba(79, 70, 229, .35);
}
.logo-mark svg { width: 18px; height: 18px; }
.nav { padding: 6px 12px; overflow-y: auto; flex: 1; }
.nav-label { font-size: 11px; font-weight: 600; text-transform: uppercase; letter-spacing: .06em; color: var(--text-3); padding: 14px 10px 6px; }
.nav a {
  display: flex; align-items: center; gap: 11px; padding: 8px 10px; border-radius: var(--radius-sm);
  color: var(--text-2); font-weight: 500; margin-bottom: 2px;
}
.nav a svg { width: 18px; height: 18px; flex-shrink: 0; }
.nav a:hover { background: var(--surface-3); color: var(--text); text-decoration: none; }
.nav a.active { background: var(--brand-50); color: var(--brand); }
.nav a .count { margin-left: auto; font-size: 11px; background: var(--red); color: #fff; border-radius: 99px; padding: 0 7px; font-weight: 600; }
.sidebar-footer { border-top: 1px solid var(--border); padding: 12px; }

.main { flex: 1; margin-left: var(--sidebar-w); min-width: 0; display: flex; flex-direction: column; }
.topbar {
  height: var(--topbar-h); display: flex; align-items: center; gap: 12px; padding: 0 24px;
  background: color-mix(in srgb, var(--surface) 85%, transparent); backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--border); position: sticky; top: 0; z-index: 1000;
}
.topbar h1 { font-size: 17px; }
.impersonation-bar { flex: none; height: var(--notice-h); display: flex; align-items: center; gap: 10px; padding: 0 16px; background: #f59e0b; color: #1c1917; font-size: 13.5px; }
body.impersonating { --notice-h: 44px; }
.impersonation-bar svg { width: 18px; height: 18px; flex: none; }
.impersonation-bar .btn { background: #1c1917; color: #fff; border-color: #1c1917; }
.topbar .spacer { flex: 1; }
.content { padding: 24px; max-width: 1400px; width: 100%; margin: 0 auto; }
.content.full { padding: 0; max-width: none; }
.menu-toggle { display: none; }

@media (max-width: 900px) {
  .sidebar { transform: translateX(-100%); }
  .sidebar.open { transform: none; box-shadow: var(--shadow-lg); }
  .main { margin-left: 0; }
  .menu-toggle { display: inline-flex; }
  .content { padding: 16px; }
}

/* ---------- Cards ---------- */
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow-sm); }
.card-header { display: flex; align-items: center; gap: 10px; padding: 16px 18px; border-bottom: 1px solid var(--border); }
.card-header h3 { flex: 1; }
.card-body { padding: 18px; }
.card-footer { padding: 12px 18px; border-top: 1px solid var(--border); background: var(--surface-2); border-radius: 0 0 var(--radius) var(--radius); }
.grid { display: grid; gap: 16px; }
.grid-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.grid-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.grid-4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.grid-auto { grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); }
@media (max-width: 1100px) { .grid-4 { grid-template-columns: repeat(2, 1fr); } .grid-3 { grid-template-columns: repeat(2, 1fr); } }
@media (max-width: 700px) { .grid-2, .grid-3, .grid-4 { grid-template-columns: 1fr; } }

.stat { padding: 16px 18px; }
.stat .label { color: var(--text-3); font-size: 12px; font-weight: 500; display: flex; align-items: center; gap: 6px; }
.stat .label svg { width: 14px; height: 14px; }
.stat .value { font-size: 24px; font-weight: 700; letter-spacing: -.02em; margin-top: 4px; }
.stat .sub { color: var(--text-3); font-size: 12px; }

/* ---------- Buttons ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 7px; height: 36px; padding: 0 14px;
  border-radius: var(--radius-sm); border: 1px solid var(--border-strong); background: var(--surface);
  color: var(--text); font: inherit; font-weight: 550; cursor: pointer; white-space: nowrap; transition: .12s;
}
.btn:hover { background: var(--surface-3); text-decoration: none; }
.btn svg { width: 16px; height: 16px; }
.btn:disabled, .btn.loading { opacity: .6; pointer-events: none; }
/* Botão processando: troca o ícone por um spinner (ou põe um na frente) */
.btn.loading { opacity: .85; position: relative; }
.btn.loading > svg, .btn.loading > i[data-lucide] { display: none; }
.btn.loading::before { content: ''; width: 14px; height: 14px; border: 2px solid currentColor; border-right-color: transparent; border-radius: 50%; animation: spin .7s linear infinite; flex: none; }
/* Tela "processando pagamento" (cobrança) */
.processing { position: fixed; inset: 0; z-index: 2000; display: flex; align-items: center; justify-content: center; background: color-mix(in srgb, var(--bg) 70%, transparent); backdrop-filter: blur(3px); }
.processing .box { background: var(--surface); border: 1px solid var(--border); border-radius: 14px; padding: 22px 26px; display: flex; gap: 14px; align-items: center; box-shadow: 0 10px 40px rgba(0,0,0,.18); max-width: 360px; }
.processing .spinner { width: 28px; height: 28px; border-width: 3px; flex: none; }
.btn-primary { background: var(--brand); border-color: var(--brand); color: #fff; }
.btn-primary:hover { background: var(--brand-600); }
.btn-danger { background: var(--red); border-color: var(--red); color: #fff; }
.btn-danger:hover { filter: brightness(.92); background: var(--red); }
.btn-success { background: var(--green); border-color: var(--green); color: #fff; }
.btn-success:hover { filter: brightness(.92); background: var(--green); }
.btn-ghost { border-color: transparent; background: transparent; color: var(--text-2); }
.btn-ghost:hover { background: var(--surface-3); color: var(--text); }
.btn-sm { height: 30px; padding: 0 10px; font-size: 13px; }
.btn-lg { height: 44px; padding: 0 20px; font-size: 15px; }
.btn-icon { width: 36px; padding: 0; }
.btn-icon.btn-sm { width: 30px; }
.btn-block { width: 100%; }
.btn-group { display: inline-flex; }
.btn-group .btn { border-radius: 0; margin-left: -1px; }
.btn-group .btn:first-child { border-radius: var(--radius-sm) 0 0 var(--radius-sm); margin-left: 0; }
.btn-group .btn:last-child { border-radius: 0 var(--radius-sm) var(--radius-sm) 0; }
.btn-group .btn.active { background: var(--brand-50); color: var(--brand); border-color: var(--brand); z-index: 1; }

/* ---------- Forms ---------- */
.field { display: flex; flex-direction: column; gap: 6px; margin-bottom: 14px; }
.field > label, .label { font-size: 13px; font-weight: 550; color: var(--text-2); }
.hint { font-size: 12px; color: var(--text-3); }
.error-text { font-size: 12px; color: var(--red); }
.phone-field { display: flex; gap: 6px; }
.phone-field .select { width: auto; flex: none; padding-right: 26px; }
.phone-field .input { flex: 1; min-width: 0; }
.input, .select, .textarea {
  width: 100%; height: 38px; padding: 0 12px; border: 1px solid var(--border-strong); border-radius: var(--radius-sm);
  background: var(--surface); color: var(--text); font: inherit; outline: none; transition: border-color .12s, box-shadow .12s;
}
.textarea { height: auto; min-height: 90px; padding: 10px 12px; resize: vertical; }
.input:focus, .select:focus, .textarea:focus { border-color: var(--brand); box-shadow: 0 0 0 3px color-mix(in srgb, var(--brand) 18%, transparent); }
.input.invalid { border-color: var(--red); }
.input-group { display: flex; }
.input-group .input { border-radius: var(--radius-sm) 0 0 var(--radius-sm); }
.input-group .btn { border-radius: 0 var(--radius-sm) var(--radius-sm) 0; margin-left: -1px; height: 38px; }
.checkbox { display: flex; align-items: center; gap: 8px; cursor: pointer; font-weight: 500; }
.checkbox input { width: 16px; height: 16px; accent-color: var(--brand); }
.switch { position: relative; width: 38px; height: 22px; flex-shrink: 0; display: inline-block; }
.switch input { opacity: 0; width: 0; height: 0; }
.switch span { position: absolute; inset: 0; background: var(--border-strong); border-radius: 99px; transition: .15s; cursor: pointer; }
.switch span::before { content: ''; position: absolute; width: 16px; height: 16px; left: 3px; top: 3px; background: #fff; border-radius: 50%; transition: .15s; box-shadow: var(--shadow-sm); }
.switch input:checked + span { background: var(--brand); }
.switch input:checked + span::before { transform: translateX(16px); }
.form-row { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 0 14px; }

/* ---------- Badges / chips ---------- */
.badge { display: inline-flex; align-items: center; gap: 5px; height: 22px; padding: 0 8px; border-radius: 99px; font-size: 12px; font-weight: 600; background: var(--gray-bg); color: var(--gray); white-space: nowrap; }
.badge svg { width: 12px; height: 12px; }
.badge-green { background: var(--green-bg); color: var(--green); }
.badge-amber { background: var(--amber-bg); color: var(--amber); }
.badge-red { background: var(--red-bg); color: var(--red); }
.badge-blue { background: var(--blue-bg); color: var(--blue); }
.badge-violet { background: var(--violet-bg); color: var(--violet); }
.badge-brand { background: var(--brand-50); color: var(--brand); }
.dot { width: 8px; height: 8px; border-radius: 50%; display: inline-block; flex-shrink: 0; }
.dot.pulse { box-shadow: 0 0 0 0 currentColor; animation: pulse 1.8s infinite; }
@keyframes pulse { 0% { box-shadow: 0 0 0 0 color-mix(in srgb, currentColor 60%, transparent); } 70% { box-shadow: 0 0 0 7px transparent; } 100% { box-shadow: 0 0 0 0 transparent; } }
.state-moving { color: var(--state-moving); background: var(--state-moving); }
.state-idle { color: var(--state-idle); background: var(--state-idle); }
.state-stopped { color: var(--state-stopped); background: var(--state-stopped); }
.state-offline, .state-inactive { color: var(--state-offline); background: var(--state-offline); }
.state-never { color: var(--state-never); background: var(--state-never); }

/* ---------- Tables ---------- */
.table-wrap { overflow-x: auto; }
.table { width: 100%; border-collapse: collapse; }
.table th { text-align: left; font-size: 12px; font-weight: 600; color: var(--text-3); text-transform: uppercase; letter-spacing: .04em; padding: 10px 14px; border-bottom: 1px solid var(--border); background: var(--surface-2); white-space: nowrap; }
.table td { padding: 11px 14px; border-bottom: 1px solid var(--border); vertical-align: middle; }
.table tr:last-child td { border-bottom: 0; }
.table tbody tr:hover { background: var(--surface-2); }
.table .num { text-align: right; font-variant-numeric: tabular-nums; }
.table tr.clickable { cursor: pointer; }

/* ---------- Avatars ---------- */
.avatar { width: 38px; height: 38px; border-radius: 50%; display: grid; place-items: center; flex-shrink: 0; font-weight: 650; font-size: 13px; color: #fff; background: var(--brand); overflow: hidden; position: relative; }
.avatar img { width: 100%; height: 100%; object-fit: cover; }
.avatar.sm { width: 30px; height: 30px; font-size: 11px; }
.avatar.lg { width: 56px; height: 56px; font-size: 18px; }
.avatar.xl { width: 84px; height: 84px; font-size: 26px; }
.avatar.square { border-radius: 12px; }
.avatar svg { width: 55%; height: 55%; }
.avatar .state-ring { position: absolute; inset: 0; border-radius: inherit; box-shadow: inset 0 0 0 2.5px currentColor; }

/* ---------- Misc ---------- */
.row { display: flex; align-items: center; gap: 10px; }
.row.wrap { flex-wrap: wrap; }
.row.between { justify-content: space-between; }
.stack { display: flex; flex-direction: column; gap: 12px; }
.muted { color: var(--text-3); }
.text-2 { color: var(--text-2); }
.small { font-size: 12px; }
.bold { font-weight: 650; }
.right { text-align: right; }
.center { text-align: center; }
.mt-1 { margin-top: 6px; } .mt-2 { margin-top: 12px; } .mt-3 { margin-top: 18px; } .mt-4 { margin-top: 24px; }
.mb-1 { margin-bottom: 6px; } .mb-2 { margin-bottom: 12px; } .mb-3 { margin-bottom: 18px; } .mb-4 { margin-bottom: 24px; }
.gap-sm { gap: 6px; }
.flex-1 { flex: 1; min-width: 0; }
.truncate { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.hidden { display: none !important; }
.page-head { display: flex; align-items: center; gap: 12px; margin-bottom: 20px; flex-wrap: wrap; }
.page-head .titles { flex: 1; min-width: 200px; }
.page-head p { color: var(--text-3); margin-top: 2px; }
.empty { padding: 48px 20px; text-align: center; color: var(--text-3); }
.empty svg { width: 40px; height: 40px; margin-bottom: 10px; opacity: .55; }
.empty h3 { color: var(--text); margin-bottom: 4px; }
.kv { display: grid; grid-template-columns: auto 1fr; gap: 8px 16px; }
.kv dt { color: var(--text-3); font-size: 13px; }
.kv dd { margin: 0; font-weight: 550; text-align: right; }
.divider-v { width: 1px; align-self: stretch; background: var(--border); }
.copy-box { display: flex; align-items: center; gap: 8px; padding: 8px 10px; background: var(--surface-3); border: 1px dashed var(--border-strong); border-radius: var(--radius-sm); font-family: var(--mono); font-size: 12.5px; word-break: break-all; }
.tag-list { display: flex; flex-wrap: wrap; gap: 6px; }
.skeleton { background: linear-gradient(90deg, var(--surface-3) 25%, var(--border) 37%, var(--surface-3) 63%); background-size: 400% 100%; animation: sk 1.4s ease infinite; border-radius: 6px; min-height: 14px; }
@keyframes sk { 0% { background-position: 100% 50%; } 100% { background-position: 0 50%; } }
.spinner { width: 18px; height: 18px; border: 2px solid var(--border-strong); border-top-color: var(--brand); border-radius: 50%; animation: spin .7s linear infinite; display: inline-block; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- Tabs ---------- */
.tabs { display: flex; gap: 2px; border-bottom: 1px solid var(--border); margin-bottom: 18px; overflow-x: auto; }
.tabs button, .tabs a { background: none; border: 0; padding: 10px 14px; font: inherit; font-weight: 550; color: var(--text-3); cursor: pointer; border-bottom: 2px solid transparent; margin-bottom: -1px; white-space: nowrap; display: inline-flex; align-items: center; gap: 6px; }
.tabs button svg { width: 15px; height: 15px; }
.tabs button:hover { color: var(--text); }
.tabs button.active, .tabs a.active { color: var(--brand); border-bottom-color: var(--brand); }
.pills { display: inline-flex; padding: 3px; background: var(--surface-3); border-radius: 10px; gap: 2px; }
.pills button { border: 0; background: transparent; padding: 5px 12px; border-radius: 8px; font: inherit; font-size: 13px; font-weight: 550; color: var(--text-2); cursor: pointer; white-space: nowrap; }
.pills button.active { background: var(--surface); color: var(--text); box-shadow: var(--shadow-sm); }

/* ---------- Modal / drawer ---------- */
.modal-backdrop { position: fixed; inset: 0; background: rgba(15, 23, 42, .45); backdrop-filter: blur(2px); z-index: 2000; display: grid; place-items: center; padding: 20px; overflow-y: auto; }
.modal { background: var(--surface); border-radius: var(--radius-lg); box-shadow: var(--shadow-lg); width: 100%; max-width: 520px; max-height: calc(100vh - 40px); display: flex; flex-direction: column; animation: pop .16s ease-out; }
.modal.lg { max-width: 760px; } .modal.xl { max-width: 1000px; }
.modal-header { display: flex; align-items: center; gap: 10px; padding: 18px 20px; border-bottom: 1px solid var(--border); }
.modal-header h3 { flex: 1; font-size: 16px; }
.modal-body { padding: 20px; overflow-y: auto; }
.modal-footer { display: flex; justify-content: flex-end; gap: 8px; padding: 14px 20px; border-top: 1px solid var(--border); }
@keyframes pop { from { transform: translateY(8px) scale(.98); opacity: 0; } to { transform: none; opacity: 1; } }

/* ---------- Toasts ---------- */
.toasts { position: fixed; right: 18px; bottom: 18px; z-index: 3000; display: flex; flex-direction: column; gap: 10px; max-width: 380px; width: calc(100% - 36px); }
.toast { display: flex; gap: 12px; align-items: flex-start; background: var(--surface); border: 1px solid var(--border); border-left: 4px solid var(--brand); border-radius: var(--radius); box-shadow: var(--shadow-lg); padding: 12px 14px; animation: slidein .2s ease-out; }
.toast svg { width: 20px; height: 20px; flex-shrink: 0; margin-top: 1px; }
.toast .t-title { font-weight: 650; }
.toast .t-msg { color: var(--text-2); font-size: 13px; }
.toast.success { border-left-color: var(--green); } .toast.success svg { color: var(--green); }
.toast.danger, .toast.error { border-left-color: var(--red); } .toast.danger svg, .toast.error svg { color: var(--red); }
.toast.warning { border-left-color: var(--amber); } .toast.warning svg { color: var(--amber); }
.toast.info svg { color: var(--brand); }
@keyframes slidein { from { transform: translateX(20px); opacity: 0; } to { transform: none; opacity: 1; } }

/* ---------- Dropdown ---------- */
.dropdown { position: relative; }
.dropdown-menu { position: absolute; right: 0; top: calc(100% + 6px); min-width: 220px; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow-lg); padding: 6px; z-index: 1500; }
.dropdown-menu a, .dropdown-menu button { display: flex; align-items: center; gap: 10px; width: 100%; padding: 8px 10px; border-radius: 8px; border: 0; background: none; font: inherit; color: var(--text); cursor: pointer; text-align: left; }
.dropdown-menu a:hover, .dropdown-menu button:hover { background: var(--surface-3); text-decoration: none; }
.dropdown-menu svg { width: 16px; height: 16px; color: var(--text-3); }
.dropdown-menu.menu-rich { min-width: 290px; }
.menu-rich a { align-items: flex-start; }
.menu-rich a svg { margin-top: 2px; flex: none; }
.menu-rich small { display: block; color: var(--text-3); font-size: 12px; line-height: 1.35; margin-top: 1px; }

/* ---------- Map page ---------- */
.map-layout { position: relative; height: calc(100vh - var(--topbar-h) - var(--notice-h, 0px)); display: flex; }
.map-panel { width: 360px; flex-shrink: 0; background: var(--surface); border-right: 1px solid var(--border); display: flex; flex-direction: column; z-index: 500; }
.map-panel .panel-head { padding: 14px; border-bottom: 1px solid var(--border); display: flex; flex-direction: column; gap: 10px; }
.map-panel .panel-list { overflow-y: auto; flex: 1; }
.map-canvas { flex: 1; position: relative; }
#map, .map { width: 100%; height: 100%; background: var(--surface-3); }
.device-item { display: flex; gap: 12px; padding: 12px 14px; border-bottom: 1px solid var(--border); cursor: pointer; align-items: center; transition: background .1s; }
.device-item:hover { background: var(--surface-2); }
.device-item.selected { background: var(--brand-50); box-shadow: inset 3px 0 0 var(--brand); }
.device-item .meta { font-size: 12px; color: var(--text-3); display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.device-item .meta svg { width: 12px; height: 12px; }
.map-overlay { position: absolute; z-index: 600; }
.map-overlay.tr { top: 14px; right: 14px; }
.map-overlay.tl { top: 14px; left: 14px; }
.map-overlay.br { bottom: 24px; right: 14px; }
.map-overlay.bl { bottom: 24px; left: 14px; }
.map-ctrl { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); display: flex; flex-direction: column; overflow: hidden; }
.map-ctrl button { width: 38px; height: 38px; border: 0; background: none; display: grid; place-items: center; cursor: pointer; color: var(--text-2); border-bottom: 1px solid var(--border); }
.map-ctrl button:last-child { border-bottom: 0; }
.map-ctrl button:hover { background: var(--surface-3); color: var(--text); }
.map-ctrl button.active { color: var(--brand); background: var(--brand-50); }
.map-ctrl svg { width: 18px; height: 18px; }
.detail-card { position: absolute; z-index: 650; right: 14px; top: 14px; width: 360px; max-height: calc(100% - 28px); overflow-y: auto; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-lg); box-shadow: var(--shadow-lg); animation: pop .16s ease-out; }
.detail-card .dc-head { padding: 16px; display: flex; gap: 12px; align-items: center; border-bottom: 1px solid var(--border); }
.detail-card .dc-body { padding: 14px 16px; }
.metric-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.metric { background: var(--surface-2); border: 1px solid var(--border); border-radius: 10px; padding: 8px 10px; }
.metric .m-label { font-size: 11px; color: var(--text-3); display: flex; align-items: center; gap: 4px; }
.metric .m-label svg { width: 12px; height: 12px; }
.metric .m-value { font-weight: 700; font-size: 15px; }
.style-switch { display: flex; gap: 6px; padding: 6px; }
.style-switch button { border: 2px solid transparent; border-radius: 10px; padding: 0; width: 64px; cursor: pointer; background: var(--surface-3); font: inherit; font-size: 11px; color: var(--text-2); overflow: hidden; }
.style-switch button img, .style-switch button .sw { width: 100%; height: 44px; display: block; object-fit: cover; }
.style-switch button.active { border-color: var(--brand); color: var(--brand); }
@media (max-width: 900px) {
  .map-panel { position: absolute; bottom: 0; left: 0; right: 0; width: auto; height: 42%; border-right: 0; border-top: 1px solid var(--border); border-radius: 18px 18px 0 0; box-shadow: var(--shadow-lg); }
  .detail-card { left: 10px; right: 10px; width: auto; top: 10px; max-height: 55%; }
}

/* Marcadores (Leaflet divIcon) */
.pl-marker { background: none !important; border: 0 !important; }
.pl-person { position: relative; width: 46px; height: 54px; }
.pl-person .bubble { width: 46px; height: 46px; border-radius: 50%; background: #fff; padding: 3px; box-shadow: 0 3px 10px rgba(0,0,0,.28); position: relative; z-index: 2; }
.pl-person .bubble .inner { width: 100%; height: 100%; border-radius: 50%; overflow: hidden; display: grid; place-items: center; color: #fff; font-weight: 700; font-size: 14px; font-family: var(--font); }
.pl-person .bubble .inner img { width: 100%; height: 100%; object-fit: cover; }
.pl-person .tail { position: absolute; left: 50%; bottom: 2px; width: 14px; height: 14px; background: #fff; transform: translateX(-50%) rotate(45deg); box-shadow: 2px 2px 4px rgba(0,0,0,.15); z-index: 1; }
.pl-person .st { position: absolute; right: -1px; top: -1px; width: 14px; height: 14px; border-radius: 50%; border: 2.5px solid #fff; z-index: 3; }
.pl-vehicle { position: relative; width: 44px; height: 44px; }
.pl-vehicle .halo { position: absolute; inset: 0; border-radius: 50%; opacity: .22; }
.pl-vehicle.moving .halo { animation: halo 2s infinite; }
@keyframes halo { 0% { transform: scale(.7); opacity: .4; } 100% { transform: scale(1.5); opacity: 0; } }
.pl-vehicle .body { position: absolute; inset: 6px; border-radius: 50%; background: #fff; box-shadow: 0 3px 10px rgba(0,0,0,.3); display: grid; place-items: center; }
.pl-vehicle .body svg { width: 22px; height: 22px; transition: transform .6s; }
.pl-vehicle .dir { position: absolute; inset: -7px; transition: transform .6s; pointer-events: none; }
.pl-vehicle .dir svg { position: absolute; top: 0; left: 50%; width: 12px; height: 9px; margin-left: -6px; }
.pl-vehicle .lock { position: absolute; right: -2px; bottom: -2px; width: 18px; height: 18px; border-radius: 50%; background: var(--red); color: #fff; display: grid; place-items: center; border: 2px solid #fff; }
.pl-vehicle .lock svg { width: 10px; height: 10px; }
.pl-label { position: absolute; top: 100%; left: 50%; transform: translateX(-50%); margin-top: 2px; background: rgba(15,23,42,.82); color: #fff; font: 600 11px var(--font); padding: 1px 7px; border-radius: 6px; white-space: nowrap; pointer-events: none; }
.pl-stop { width: 26px; height: 26px; border-radius: 50%; background: #fff; border: 2px solid var(--state-stopped); display: grid; place-items: center; font: 700 11px var(--font); color: var(--state-stopped); box-shadow: var(--shadow); }
.pl-flag { width: 28px; height: 28px; border-radius: 50%; display: grid; place-items: center; color: #fff; box-shadow: var(--shadow); border: 2px solid #fff; }
.pl-flag svg { width: 14px; height: 14px; }
.pl-event { width: 22px; height: 22px; border-radius: 50%; display: grid; place-items: center; color: #fff; border: 2px solid #fff; box-shadow: var(--shadow); }
.pl-event svg { width: 11px; height: 11px; }
.leaflet-popup-content-wrapper { border-radius: 12px !important; box-shadow: var(--shadow-lg) !important; background: var(--surface) !important; color: var(--text) !important; }
.leaflet-popup-tip { background: var(--surface) !important; }
.leaflet-popup-content { margin: 12px 14px !important; font: 13px var(--font) !important; }
.leaflet-control-attribution { font-size: 10px !important; background: color-mix(in srgb, var(--surface) 75%, transparent) !important; color: var(--text-3) !important; }
.leaflet-control-attribution a { color: var(--text-2) !important; }
.leaflet-bar a { background: var(--surface) !important; color: var(--text) !important; border-color: var(--border) !important; }
.leaflet-container { font-family: var(--font); }

/* Histórico */
.playback { display: flex; align-items: center; gap: 12px; padding: 12px 16px; background: var(--surface); border-top: 1px solid var(--border); }
.playback input[type=range] { flex: 1; accent-color: var(--brand); }
.timeline { position: relative; padding-left: 26px; }
.timeline::before { content: ''; position: absolute; left: 10px; top: 6px; bottom: 6px; width: 2px; background: var(--border); }
.timeline .tl-item { position: relative; padding: 8px 10px; border-radius: 10px; cursor: pointer; margin-bottom: 4px; }
.timeline .tl-item:hover { background: var(--surface-2); }
.timeline .tl-item .tl-dot { position: absolute; left: -22px; top: 13px; width: 14px; height: 14px; border-radius: 50%; border: 3px solid var(--surface); box-shadow: 0 0 0 1px var(--border-strong); }
.speed-legend { display: flex; align-items: center; gap: 10px; font-size: 11px; color: var(--text-3); }
.speed-legend i { display: inline-block; width: 18px; height: 4px; border-radius: 2px; margin-right: 3px; vertical-align: middle; }

/* Wizard */
.steps { display: flex; gap: 8px; margin-bottom: 24px; }
.steps .step { flex: 1; display: flex; align-items: center; gap: 8px; font-size: 13px; font-weight: 600; color: var(--text-3); }
.steps .step .n { width: 26px; height: 26px; border-radius: 50%; display: grid; place-items: center; background: var(--surface-3); flex-shrink: 0; font-size: 12px; }
.steps .step.done .n { background: var(--green); color: #fff; }
.steps .step.active { color: var(--text); }
.steps .step.active .n { background: var(--brand); color: #fff; }
.steps .step .bar { flex: 1; height: 2px; background: var(--border); }
.choice { border: 2px solid var(--border); border-radius: var(--radius); padding: 18px; cursor: pointer; transition: .12s; background: var(--surface); text-align: left; font: inherit; color: inherit; width: 100%; }
.choice:hover { border-color: var(--border-strong); }
.choice.selected { border-color: var(--brand); background: var(--brand-50); }
.choice .c-icon { width: 44px; height: 44px; border-radius: 12px; display: grid; place-items: center; background: var(--brand-50); color: var(--brand); margin-bottom: 10px; }
.choice .c-icon svg { width: 22px; height: 22px; }
.cat-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(96px, 1fr)); gap: 8px; }
.cat-grid button { border: 2px solid var(--border); background: var(--surface); border-radius: 12px; padding: 12px 6px; cursor: pointer; font: inherit; font-size: 12px; font-weight: 550; color: var(--text-2); display: flex; flex-direction: column; align-items: center; gap: 6px; }
.cat-grid button svg { width: 24px; height: 24px; }
.cat-grid button.selected { border-color: var(--brand); color: var(--brand); background: var(--brand-50); }
.plan-card { border: 2px solid var(--border); border-radius: var(--radius-lg); padding: 20px; cursor: pointer; background: var(--surface); position: relative; transition: .12s; }
.plan-card.selected { border-color: var(--brand); box-shadow: 0 0 0 4px color-mix(in srgb, var(--brand) 15%, transparent); }
.plan-card .price { font-size: 28px; font-weight: 750; letter-spacing: -.02em; }
.plan-card .price small { font-size: 13px; color: var(--text-3); font-weight: 500; }
.plan-card ul { list-style: none; padding: 0; margin: 12px 0 0; display: flex; flex-direction: column; gap: 6px; }
.plan-card li { display: flex; gap: 8px; align-items: flex-start; font-size: 13px; color: var(--text-2); }
.plan-card li svg { width: 16px; height: 16px; color: var(--green); flex-shrink: 0; margin-top: 2px; }
.progress-steps { display: flex; flex-direction: column; gap: 0; }
.progress-steps .ps { display: flex; gap: 14px; padding-bottom: 18px; position: relative; }
.progress-steps .ps::before { content: ''; position: absolute; left: 15px; top: 32px; bottom: 0; width: 2px; background: var(--border); }
.progress-steps .ps:last-child::before { display: none; }
.progress-steps .ps .ic { width: 32px; height: 32px; border-radius: 50%; background: var(--surface-3); display: grid; place-items: center; flex-shrink: 0; color: var(--text-3); z-index: 1; }
.progress-steps .ps .ic svg { width: 16px; height: 16px; }
.progress-steps .ps.done .ic { background: var(--green); color: #fff; }
.progress-steps .ps.current .ic { background: var(--brand); color: #fff; }
.qr-box { display: grid; place-items: center; padding: 16px; background: #fff; border-radius: var(--radius); border: 1px solid var(--border); }
.qr-box img, .qr-box canvas, .qr-box svg { width: 220px; height: 220px; }

/* Auth / landing */
.auth-wrap { min-height: 100vh; display: grid; grid-template-columns: 1fr 1fr; }
.auth-side { background: radial-gradient(1200px 600px at 10% 10%, #6366f1 0%, transparent 60%), radial-gradient(900px 500px at 90% 90%, #06b6d4 0%, transparent 55%), #0b1023; color: #fff; padding: 48px; display: flex; flex-direction: column; justify-content: space-between; position: relative; overflow: hidden; }
.auth-side h2 { font-size: 34px; line-height: 1.15; letter-spacing: -.02em; max-width: 460px; }
.auth-side p { color: rgba(255,255,255,.75); max-width: 440px; margin-top: 12px; font-size: 15px; }
.auth-form { display: grid; place-items: center; padding: 32px; background: var(--surface); }
.auth-form .box { width: 100%; max-width: 380px; }
@media (max-width: 900px) { .auth-wrap { grid-template-columns: 1fr; } .auth-side { display: none; } }

/* JSON / API docs */
.json { background: #0f172a; color: #e2e8f0; border-radius: var(--radius-sm); padding: 12px 14px; overflow: auto; max-height: 420px; font-family: var(--mono); font-size: 12px; line-height: 1.55; margin: 0; white-space: pre; }
.json .k { color: #93c5fd; } .json .s { color: #86efac; } .json .n { color: #fca5a5; } .json .b { color: #c4b5fd; } .json .z { color: #94a3b8; }
.method { display: inline-block; min-width: 58px; text-align: center; font: 700 11px var(--mono); padding: 3px 6px; border-radius: 6px; color: #fff; }
.method.GET { background: #0ea5e9; } .method.POST { background: #16a34a; } .method.PUT, .method.PATCH { background: #d97706; } .method.DELETE { background: #dc2626; }
.endpoint { border: 1px solid var(--border); border-radius: var(--radius); margin-bottom: 10px; background: var(--surface); overflow: hidden; }
.endpoint > .ep-head { display: flex; align-items: center; gap: 10px; padding: 10px 14px; cursor: pointer; }
.endpoint > .ep-head:hover { background: var(--surface-2); }
.endpoint .ep-uri { font-family: var(--mono); font-size: 13px; font-weight: 600; }
.endpoint .ep-body { border-top: 1px solid var(--border); padding: 16px; display: grid; gap: 16px; }

/* Print (relatórios) */
@media print {
  .sidebar, .topbar, .no-print { display: none !important; }
  .main { margin: 0; }
  .card { box-shadow: none; break-inside: avoid; }
}

/* Agrupamento de marcadores no mapa (Leaflet.markercluster) */
.pl-cluster { background: none; }
.pl-cluster span { display: grid; place-items: center; width: 40px; height: 40px; border-radius: 50%; background: var(--brand); color: #fff; font-weight: 700; font-size: 13px; border: 3px solid #fff; box-shadow: 0 2px 8px rgba(0,0,0,.3); }

/* Seletor de tipo de veículo e cor (dispositivo e ativação) */
.cat-group { font-size: 11px; font-weight: 700; text-transform: uppercase; letter-spacing: .05em; color: var(--text-3); margin: 10px 0 6px; }
.color-swatches { display: flex; flex-wrap: wrap; gap: 8px; }
.color-swatches button { width: 30px; height: 30px; border-radius: 50%; border: 2px solid var(--border-strong); cursor: pointer; }
.color-swatches button.selected { outline: 3px solid var(--brand); outline-offset: 2px; }


/* Ação destrutiva discreta e avisos em bloco */
.btn-danger-ghost { color: var(--red); }
.btn-danger-ghost:hover { background: var(--red-bg, rgba(220, 38, 38, .08)); color: var(--red); }
.alert { padding: 10px 12px; border-radius: 10px; border: 1px solid var(--border); background: var(--surface-2); }
.alert-warning { background: var(--amber-bg, #fffbeb); border-color: transparent; color: var(--text); }

/* Chat do suporte */
.chat { display: flex; flex-direction: column; gap: 10px; max-height: 55vh; overflow-y: auto; padding: 4px; }
.chat .msg { max-width: 80%; padding: 8px 12px; border-radius: 14px; background: var(--surface-2); word-break: break-word; }
.chat .msg > span { white-space: pre-wrap; }
.chat .msg.mine { align-self: flex-end; background: var(--brand); color: #fff; border-bottom-right-radius: 4px; }
.chat .msg:not(.mine) { border-bottom-left-radius: 4px; }
.chat .msg .meta { font-size: 11px; opacity: .7; margin-top: 4px; }
.chat .msg img { max-width: 220px; border-radius: 8px; margin-top: 6px; display: block; }
.ticket-list .item { padding: 10px 12px; border-bottom: 1px solid var(--border); cursor: pointer; }
.ticket-list .item:hover, .ticket-list .item.active { background: var(--surface-2); }
.ticket-list .item .dot-unread { width: 8px; height: 8px; border-radius: 50%; background: var(--brand); display: inline-block; }
.input-sm, .select-sm { height: 32px; font-size: 13px; padding-top: 4px; padding-bottom: 4px; }
