:root {
  --bg: #ffffff; --fg: #0f172a; --muted: #64748b; --line: #e2e8f0; --soft: #f1f5f9;
  --brand: #0f766e; --ok: #16a34a; --warn: #d97706; --bad: #dc2626;
  --shadow: 0 6px 24px rgba(15, 23, 42, .14), 0 1px 3px rgba(15, 23, 42, .08);
  --r: 16px;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  color: var(--fg);
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; overflow: hidden; background: var(--soft); }
[hidden] { display: none !important; }
button { font: inherit; cursor: pointer; }
code { font-family: ui-monospace, Consolas, monospace; background: var(--soft); padding: 1px 6px; border-radius: 6px; }

/* ---------- login ---------- */
.login { position: fixed; inset: 0; display: grid; place-items: center; padding: 24px;
  background: linear-gradient(160deg, #0f766e, #134e4a); }
.login-card { width: min(360px, 100%); background: var(--bg); border-radius: 20px; padding: 32px 24px;
  display: grid; gap: 12px; text-align: center; box-shadow: var(--shadow); }
.login-card img { margin: 0 auto; }
.login-card h1 { margin: 4px 0 0; font-size: 24px; }
.login-card p { margin: 0 0 8px; color: var(--muted); }
input { font: inherit; padding: 12px 14px; border: 1px solid var(--line); border-radius: 12px; width: 100%; }
input:focus { outline: 2px solid var(--brand); border-color: transparent; }
.login-card button, .add-form button[type=submit] { padding: 12px; border: 0; border-radius: 12px; background: var(--brand); color: #fff; font-weight: 600; }
.error { color: var(--bad); min-height: 1.2em; margin: 0; }

/* ---------- mapa ---------- */
#app, #map { position: fixed; inset: 0; }
.map-error { position: fixed; top: 76px; left: 50%; transform: translateX(-50%); width: min(520px, calc(100% - 24px));
  background: #fef2f2; color: #991b1b; border: 1px solid #fecaca; padding: 12px 14px; border-radius: 12px; z-index: 5; margin: 0; }

/* barra superior */
.topbar { position: fixed; top: calc(10px + env(safe-area-inset-top)); left: 10px; right: 10px; z-index: 4;
  display: flex; justify-content: space-between; align-items: center; pointer-events: none; }
.topbar > * { pointer-events: auto; }
.brand { background: var(--bg); box-shadow: var(--shadow); border-radius: 999px; padding: 8px 14px; display: flex; gap: 10px; align-items: center; }
.live { display: inline-flex; align-items: center; gap: 6px; font-size: 12px; color: var(--muted); }
.live i { width: 8px; height: 8px; border-radius: 50%; background: var(--muted); }
.live.on i { background: var(--ok); box-shadow: 0 0 0 0 rgba(22, 163, 74, .6); animation: beat 2s infinite; }
.live.on { color: var(--ok); }
.actions { display: flex; gap: 8px; }
.icon-btn { width: 42px; height: 42px; border-radius: 50%; border: 0; background: var(--bg); box-shadow: var(--shadow); display: grid; place-items: center; }
.icon-btn svg { width: 22px; height: 22px; fill: none; stroke: var(--fg); stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }

/* painel / lista */
.panel { position: fixed; z-index: 3; background: var(--bg); box-shadow: var(--shadow); overflow: auto;
  left: 0; right: 0; bottom: 0; max-height: 42vh; border-radius: 20px 20px 0 0; padding: 6px 12px calc(12px + env(safe-area-inset-bottom)); }
.grip { width: 40px; height: 4px; border-radius: 4px; background: var(--line); margin: 4px auto 8px; }
@media (min-width: 760px) {
  .panel { top: 72px; left: 10px; right: auto; bottom: auto; width: 340px; max-height: calc(100vh - 90px); border-radius: var(--r); padding: 8px; }
  .grip { display: none; }
}
.list { list-style: none; margin: 0; padding: 0; display: grid; gap: 6px; }
.empty { color: var(--muted); text-align: center; padding: 12px; margin: 0; }
.card { border-radius: 14px; padding: 10px; cursor: pointer; border: 1px solid transparent; }
.card:hover { background: var(--soft); }
.card.sel { border-color: var(--c); background: color-mix(in srgb, var(--c) 7%, white); }
.row { display: flex; gap: 12px; align-items: center; }
.avatar { flex: none; width: 44px; height: 44px; border-radius: 50%; background: var(--c); color: #fff; font-weight: 700; font-size: 18px;
  display: grid; place-items: center; position: relative; }
.avatar.moving::after { content: ""; position: absolute; inset: -4px; border-radius: 50%; border: 2px solid var(--ok); animation: spin-pulse 1.6s infinite; }
.avatar.stale { filter: grayscale(1); opacity: .6; }
.info { min-width: 0; }
.name { font-weight: 600; display: flex; gap: 8px; align-items: center; }
.batt { font-size: 12px; font-weight: 500; color: var(--muted); background: var(--soft); padding: 1px 7px; border-radius: 999px; }
.batt.low { color: var(--bad); background: #fef2f2; }
.status { font-size: 14px; color: var(--muted); }
.status.moving { color: var(--ok); font-weight: 600; }
.status.stale { color: var(--warn); }
.updated { font-size: 12px; color: var(--muted); }
.more { display: flex; justify-content: space-between; align-items: center; gap: 8px; margin-top: 10px; flex-wrap: wrap; }
.ranges { display: flex; background: var(--soft); border-radius: 10px; padding: 3px; }
.ranges button { border: 0; background: none; padding: 6px 10px; border-radius: 8px; font-size: 13px; color: var(--muted); }
.ranges button.on { background: var(--bg); color: var(--fg); font-weight: 600; box-shadow: 0 1px 3px rgba(0,0,0,.12); }
.go { font-size: 14px; font-weight: 600; color: var(--brand); text-decoration: none; padding: 6px 4px; }

/* marcador no mapa */
.pin { --c: #2563eb; --b: 0deg; position: relative; width: 40px; height: 40px; transform: translateY(50%); cursor: pointer; }
.pin .dot { position: absolute; inset: 0; border-radius: 50%; background: var(--c); color: #fff; font: 700 17px system-ui, sans-serif;
  display: grid; place-items: center; border: 3px solid #fff; box-shadow: 0 2px 8px rgba(0,0,0,.35); transition: transform .2s; }
.pin.sel .dot { transform: scale(1.18); }
.pin .dot.photo { border-color: var(--c); outline: 2px solid #fff; }
.pin .dot img, .avatar img { width: 100%; height: 100%; object-fit: cover; border-radius: 50%; display: block; user-select: none; }
.pin .dot.photo img { background: #fff; }
.pin .tag { position: absolute; top: 44px; left: 50%; transform: translateX(-50%); white-space: nowrap; font: 600 12px system-ui, sans-serif;
  background: #fff; color: #0f172a; padding: 2px 8px; border-radius: 999px; box-shadow: 0 1px 4px rgba(0,0,0,.25); }
.pin .pulse { position: absolute; inset: 0; border-radius: 50%; background: var(--c); opacity: 0; }
.pin.moving .pulse { animation: ripple 1.8s ease-out infinite; }
.pin .arrow { position: absolute; inset: -12px; transform: rotate(var(--b)); display: none; transition: transform .6s; }
.pin.has-dir .arrow { display: block; }
.pin .arrow::before { content: ""; position: absolute; left: 50%; top: 0; transform: translateX(-50%);
  border-left: 7px solid transparent; border-right: 7px solid transparent; border-bottom: 10px solid var(--c); filter: drop-shadow(0 0 1px #fff); }
.pin.stale .dot { filter: grayscale(1); opacity: .65; }

@keyframes ripple { 0% { transform: scale(1); opacity: .55; } 100% { transform: scale(2.6); opacity: 0; } }
@keyframes beat { 0% { box-shadow: 0 0 0 0 rgba(22,163,74,.6); } 70% { box-shadow: 0 0 0 8px rgba(22,163,74,0); } 100% { box-shadow: 0 0 0 0 rgba(22,163,74,0); } }
@keyframes spin-pulse { 0% { transform: scale(.95); opacity: 1; } 100% { transform: scale(1.25); opacity: 0; } }

/* diálogo de membros */
dialog { border: 0; border-radius: 20px; padding: 20px; width: min(520px, calc(100% - 20px)); max-height: calc(100% - 40px); box-shadow: var(--shadow); }
dialog::backdrop { background: rgba(15, 23, 42, .45); }
.dlg-head { display: flex; justify-content: space-between; align-items: center; }
.dlg-head h2 { margin: 0; }
.dlg-head .icon-btn { box-shadow: none; background: var(--soft); }
.admin-list { list-style: none; padding: 0; margin: 16px 0; display: grid; gap: 8px; }
.admin-list li { display: flex; align-items: center; gap: 10px; }
.admin-list .avatar { width: 36px; height: 36px; font-size: 15px; }
.a-name { flex: 1; display: grid; font-weight: 600; min-width: 0; }
.a-name small { font-weight: 400; color: var(--muted); }
.link-btn { border: 0; background: none; color: var(--brand); font-weight: 600; padding: 6px; }
.link-btn.danger { color: var(--bad); }
.add-form { display: grid; gap: 10px; border-top: 1px solid var(--line); padding-top: 16px; }
.add-form h3, .setup h3 { margin: 0; font-size: 16px; }
.palette { display: flex; gap: 8px; flex-wrap: wrap; }
.palette button { width: 30px; height: 30px; border-radius: 50%; border: 3px solid #fff; background: var(--c); box-shadow: 0 0 0 1px var(--line); }
.palette button.on { box-shadow: 0 0 0 2px var(--fg); }
.setup { margin-top: 16px; padding: 14px; border-radius: 14px; background: #f0fdfa; border: 1px solid #99f6e4; }
.setup ol { padding-left: 20px; margin: 10px 0; display: grid; gap: 8px; }
.setup dl { display: grid; grid-template-columns: auto 1fr; gap: 4px 10px; margin: 8px 0 0; }
.setup dt { color: var(--muted); }
.setup dd { margin: 0; word-break: break-all; }
.muted { color: var(--muted); }
#logoutBtn { margin-top: 12px; color: var(--muted); }
