:root {
  --navy: #0b1424;
  --navy-2: #111c30;
  --blue: #2f7bf6;
  --blue-d: #1f6ae8;
  --ink: #0f172a;
  --ink-2: #475569;
  --muted: #94a3b8;
  --line: #eef1f5;
  --bg: #eaeef3;
  --card: #ffffff;
  --red: #ef4444;
  --green: #22c55e;
  --amber: #f59e0b;
  --shadow: 0 12px 40px rgba(15, 23, 42, .16);
  --shadow-sm: 0 4px 16px rgba(15, 23, 42, .08);
}
* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
  font-family: "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  color: var(--ink);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
}

/* ---------- login ---------- */
.login-body {
  display: flex; align-items: center; justify-content: center;
  background: radial-gradient(1200px 600px at 30% -10%, #1e3a8a 0%, #0b1424 55%);
}
.login-card {
  background: var(--card); border-radius: 22px; padding: 40px 36px;
  width: 360px; box-shadow: 0 30px 70px rgba(0,0,0,.45); text-align: center;
}
.login-logo { width: 92px; height: auto; margin-bottom: 8px; }
.login-logo-full { width: 100%; max-width: 300px; height: auto; margin: 4px auto 22px; display: block; }
.brand-word { margin: 2px 0; font-size: 30px; font-weight: 800; letter-spacing: .01em; color: #0d1524; }
.brand-word span { color: var(--blue); }
.brand-line {
  height: 3px; width: 190px; max-width: 80%; margin: 8px auto 6px; border-radius: 2px;
  background: linear-gradient(90deg, #2f7bf6 0%, #2f7bf6 46%, #16a34a 54%, #16a34a 100%);
}
.login-sub { margin: 0 0 24px; color: var(--muted); font-size: 12px; text-transform: uppercase; letter-spacing: .22em; font-weight: 600; }
.login-card form { text-align: left; }
.pw-wrap { position: relative; display: block; }
.pw-wrap input { padding-right: 78px; }
.pw-eye {
  position: absolute; right: 8px; top: 50%; transform: translateY(-50%);
  background: none; border: none; color: var(--blue); font-size: 12px; font-weight: 700;
  cursor: pointer; padding: 4px 6px;
}

/* ---------- layout raiz ---------- */
#map { position: fixed; inset: 0 0 0 72px; z-index: 1; }

/* barra de ícones */
.rail {
  position: fixed; top: 0; left: 0; bottom: 0; width: 72px; z-index: 1000;
  background: linear-gradient(180deg, var(--navy), var(--navy-2));
  display: flex; flex-direction: column; align-items: center;
  padding: 16px 0; gap: 8px;
}
.rail-logo { width: 46px; height: auto; margin-bottom: 14px; background: #fff; border-radius: 12px; padding: 5px 4px; box-sizing: border-box; }
.rail-btn {
  width: 46px; height: 46px; border: none; border-radius: 14px; cursor: pointer;
  background: transparent; color: #8ea0bd; display: flex; align-items: center; justify-content: center;
  transition: all .15s;
}
.rail-btn svg { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.rail-btn:hover { background: rgba(255,255,255,.07); color: #cdd8ea; }
.rail-btn.active { background: var(--blue); color: #fff; box-shadow: 0 6px 16px rgba(47,123,246,.45); }
.rail-bottom { margin-top: auto; }

/* dock de painéis flutuantes */
.dock {
  position: fixed; top: 18px; left: 90px; z-index: 900;
  width: 380px; max-width: calc(100vw - 108px);
  max-height: calc(100vh - 36px); display: flex; flex-direction: column; gap: 14px;
  overflow-y: auto; padding-right: 2px;
}
.dock::-webkit-scrollbar { width: 0; }

.card {
  background: var(--card); border-radius: 20px; box-shadow: var(--shadow);
  padding: 18px; border: 1px solid rgba(255,255,255,.6);
}
.card-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 12px; }
.card-head h2 { font-size: 16px; font-weight: 700; margin: 0; letter-spacing: -.01em; }
.count { color: var(--muted); font-weight: 600; }
.card h3 { font-size: 14px; margin: 14px 0 8px; }
.card hr { border: none; border-top: 1px solid var(--line); margin: 18px 0; }
.linkbtn { background: none; border: none; color: var(--blue); font-weight: 600; font-size: 13px; cursor: pointer; }

/* ---------- card de detalhe do veículo ---------- */
.vcard { background: var(--card); border-radius: 20px; box-shadow: var(--shadow); padding: 18px; }
.vcard-top { display: flex; align-items: center; gap: 12px; }
.avatar { width: 46px; height: 46px; border-radius: 50%; background: var(--navy); color: #fff; display: flex; align-items: center; justify-content: center; flex-shrink: 0; }
.avatar svg { width: 24px; height: 24px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.vcard-name { flex: 1; min-width: 0; }
.vcard-name .plate { font-size: 18px; font-weight: 800; letter-spacing: -.02em; line-height: 1.1; }
.vcard-name .sub { color: var(--ink-2); font-size: 14px; }
.vcard-x { background: none; border: none; color: var(--muted); cursor: pointer; font-size: 20px; line-height: 1; padding: 4px; }
.vcard-x:hover { color: var(--ink); }

.pill { display: inline-flex; align-items: center; gap: 7px; margin: 14px 0; padding: 8px 14px; border-radius: 999px; font-weight: 700; font-size: 14px; }
.pill .d { width: 9px; height: 9px; border-radius: 50%; }
.pill.mov { background: #dcfce7; color: #15803d; } .pill.mov .d { background: var(--green); }
.pill.par { background: #fee2e2; color: #b91c1c; } .pill.par .d { background: var(--red); }
.pill.off { background: #eef1f5; color: #64748b; } .pill.off .d { background: var(--muted); }

.vrow { display: flex; align-items: center; gap: 12px; padding: 12px 0; border-top: 1px solid var(--line); }
.vrow:first-of-type { border-top: none; }
.vrow-ic { width: 40px; height: 40px; border-radius: 12px; background: #f4f6f9; color: var(--ink-2); display: flex; align-items: center; justify-content: center; flex-shrink: 0; }
.vrow-ic.red { background: #fef2f2; color: var(--red); }
.vrow-ic svg { width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.vrow-txt { flex: 1; min-width: 0; }
.vrow-txt .lbl { color: var(--muted); font-size: 12px; }
.vrow-txt .val { font-weight: 700; font-size: 15px; }
.vrow-txt .val small { color: var(--red); font-weight: 600; }
.signal { color: var(--green); }

.vcard-actions { display: flex; gap: 8px; margin-top: 14px; }
.vcard-actions .btn { flex: 1; justify-content: center; gap: 6px; font-size: 13px; padding: 10px 8px; }
.vcard-actions .btn svg { width: 16px; height: 16px; }

/* ---------- lista de veículos ---------- */
.vlist { list-style: none; margin: 0; padding: 0; }
.vlist li {
  display: flex; align-items: center; gap: 12px; padding: 12px; margin: 0 -6px; border-radius: 14px; cursor: pointer;
}
.vlist li:hover { background: #f4f6f9; }
.vlist li.selected { background: #eef4ff; }
.vli-dot { width: 9px; height: 9px; border-radius: 50%; flex-shrink: 0; }
.vli-av { width: 40px; height: 40px; border-radius: 50%; background: var(--navy); color: #fff; display: flex; align-items: center; justify-content: center; flex-shrink: 0; }
.vli-av svg { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 2; }
.vli-av.off { background: #cbd5e1; }
.vli-main { flex: 1; min-width: 0; }
.vli-title { font-weight: 700; font-size: 14px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.vli-sub { font-size: 12.5px; font-weight: 600; }
.vli-sub.mov { color: var(--green); } .vli-sub.par { color: var(--red); } .vli-sub.off { color: var(--muted); }
.vli-right { text-align: right; color: var(--ink-2); font-size: 12px; max-width: 96px; }
.vli-chev { color: var(--muted); }
.vli-actions { display: none; }

/* ---------- formulários ---------- */
label { display: block; font-size: 13px; color: var(--ink-2); font-weight: 600; margin: 12px 0 0; }
input[type=text], input[type=password], input[type=date], select {
  width: 100%; padding: 11px 12px; border: 1px solid #dde3ea; border-radius: 12px;
  font-size: 14px; margin-top: 5px; background: #fff; color: var(--ink); font-family: inherit;
}
input:focus, select:focus { outline: none; border-color: var(--blue); box-shadow: 0 0 0 3px rgba(47,123,246,.15); }
input[type=color] { width: 52px; height: 36px; border: 1px solid #dde3ea; border-radius: 8px; padding: 3px; }

.btn {
  border: 1px solid #dde3ea; background: #fff; color: var(--ink); display: inline-flex; align-items: center;
  padding: 11px 16px; border-radius: 12px; font-size: 14px; font-weight: 600; cursor: pointer; font-family: inherit;
  transition: all .12s;
}
.btn svg { fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.btn:hover { background: #f4f6f9; }
.btn-primary { background: var(--blue); border-color: var(--blue); color: #fff; }
.btn-primary:hover { background: var(--blue-d); }
.btn-block { width: 100%; justify-content: center; margin-top: 14px; }
.btn-small { padding: 5px 10px; font-size: 12px; border-radius: 9px; }
.btn-danger { color: var(--red); border-color: #fecaca; }

.erro { color: var(--red); font-size: 13px; margin-top: 8px; }
.muted { color: var(--muted); font-size: 12.5px; line-height: 1.5; }
.user-chip { display: flex; align-items: center; gap: 8px; font-size: 13px; color: var(--ink-2); background: #f4f6f9; padding: 10px 12px; border-radius: 12px; }
.dot-online { width: 9px; height: 9px; border-radius: 50%; background: var(--green); }

.resumo { background: #eff5ff; border: 1px solid #d3e3ff; border-radius: 14px; padding: 12px 14px; font-size: 13px; margin-top: 14px; color: #1e40af; }
.tabela { width: 100%; border-collapse: collapse; margin-top: 14px; font-size: 13px; }
.tabela th, .tabela td { text-align: left; padding: 9px 6px; border-bottom: 1px solid var(--line); }
.tabela th { font-size: 11px; text-transform: uppercase; color: var(--muted); letter-spacing: .05em; }
input[type=range] { width: 100%; margin-top: 8px; accent-color: var(--blue); }

.event-list { list-style: none; margin: 6px 0 0; padding: 0; font-size: 12.5px; }
.event-list li { padding: 9px 4px; border-bottom: 1px solid var(--line); }
.ev-entrou { color: var(--green); font-weight: 700; } .ev-saiu { color: var(--red); font-weight: 700; }

/* passos do assistente */
.steps { list-style: none; margin: 14px 0 0; padding: 0; }
.step { border: 1px solid var(--line); border-radius: 14px; padding: 12px; margin-bottom: 8px; }
.step-title { font-weight: 700; font-size: 13px; margin-bottom: 8px; }
.step-cmd { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; margin-bottom: 6px; }
.step-cmd a.btn { text-decoration: none; }
code { background: #f1f5f9; border: 1px solid var(--line); border-radius: 7px; padding: 3px 7px; font-size: 12.5px; }

/* modal */
dialog { border: none; border-radius: 20px; padding: 0; box-shadow: var(--shadow); width: 340px; }
dialog::backdrop { background: rgba(11, 20, 36, .55); backdrop-filter: blur(2px); }
.dlg-form { padding: 22px 24px; }
.dlg-form h2 { margin: 0 0 6px; font-size: 18px; }
.dlg-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 18px; }

/* marcador de veículo */
.veh-marker { display: flex; align-items: center; justify-content: center; }
.veh-pin {
  width: 40px; height: 40px; border-radius: 50% 50% 50% 0; transform: rotate(-45deg);
  box-shadow: 0 6px 16px rgba(15,23,42,.4); display: flex; align-items: center; justify-content: center;
  border: 3px solid #fff;
}
.veh-pin svg { transform: rotate(45deg); width: 18px; height: 18px; fill: #fff; }
.veh-label {
  position: absolute; top: -26px; left: 50%; transform: translateX(-50%);
  background: var(--navy); color: #fff; font-size: 11px; font-weight: 700; padding: 3px 8px; border-radius: 8px; white-space: nowrap;
}

/* leaflet tweaks */
.leaflet-control-zoom { border: none !important; box-shadow: var(--shadow-sm) !important; border-radius: 12px !important; overflow: hidden; }
.leaflet-control-zoom a { border: none !important; }
.leaflet-popup-content-wrapper { border-radius: 14px; }

/* modo funcionário (visualização): esconde tudo que altera o sistema */
.viewer #btnNovoDevice,
.viewer .rail-btn[data-view="setup"],
.viewer #btnNovaCerca,
.viewer #fenceList .btn-danger,
.viewer #userAdmin { display: none !important; }

/* modo gestor: gerencia a frota (cercas), mas não cadastra rastreador, nem configura aparelho, nem mexe em usuários */
.gestor #btnNovoDevice,
.gestor .rail-btn[data-view="setup"],
.gestor #userAdmin { display: none !important; }

@media (max-width: 720px) {
  #map { inset: 0 0 45% 72px; }
  .dock { top: auto; bottom: 12px; left: 84px; width: calc(100vw - 96px); max-height: 42vh; }
}
