:root {
  --bg: #f4f6fa;
  --card: #ffffff;
  --text: #101828;
  --sub: #667085;
  --line: #e7eaf0;
  --brand: #2f6fed;
  --brand-soft: #eaf0ff;
  --ok: #12a150;
  --warn: #e8a317;
  --bad: #e5484d;
  --shadow: 0 8px 30px rgba(16, 24, 40, 0.1);
  --radius: 14px;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

/* hidden 必须能压住 display:block/flex 等自定义样式 */
[hidden] { display: none !important; }

html, body {
  margin: 0;
  height: 100%;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif;
  color: var(--text);
  background: var(--bg);
  overflow: hidden;
}

#map { position: fixed; inset: 0; background: #e9edf3; }

/* ---------------- 顶栏 ---------------- */
.topbar {
  position: fixed;
  top: 0; left: 0; right: 0;
  height: 58px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 14px;
  background: rgba(255, 255, 255, 0.92);
  backdrop-filter: saturate(180%) blur(12px);
  border-bottom: 1px solid var(--line);
  z-index: 1200;
}

.brand { display: flex; align-items: center; gap: 10px; }

.brand-mark {
  width: 26px; height: 26px;
  border-radius: 8px;
  background: var(--brand);
  position: relative;
  display: inline-block;
  flex: none;
}
.brand-mark::after {
  content: "";
  position: absolute;
  inset: 0;
  margin: auto;
  width: 8px; height: 8px;
  border-radius: 50%;
  background: #fff;
  box-shadow: 0 0 0 3px rgba(255, 255, 255, 0.35);
}
.brand-mark.lg { width: 44px; height: 44px; border-radius: 13px; }
.brand-mark.lg::after { width: 13px; height: 13px; }

.brand-text { display: flex; flex-direction: column; line-height: 1.15; }
.brand-text strong { font-size: 15px; letter-spacing: .2px; }
.brand-text small { color: var(--sub); font-size: 11px; margin-top: 2px; }

.topbar-right { display: flex; align-items: center; gap: 8px; }

.live {
  display: inline-flex; align-items: center; gap: 6px;
  font-size: 12px; color: var(--sub);
  padding: 5px 10px; border-radius: 20px;
  background: #f2f4f8;
}
.live i { width: 7px; height: 7px; border-radius: 50%; background: var(--warn); }
.live.on i { background: var(--ok); box-shadow: 0 0 0 3px rgba(18, 161, 80, .15); }
.live.off i { background: var(--bad); }

.icon-btn {
  border: 1px solid var(--line);
  background: #fff;
  color: var(--text);
  font-size: 12.5px;
  padding: 6px 11px;
  border-radius: 9px;
  cursor: pointer;
  transition: .15s;
}
.icon-btn:hover { background: #f6f8fc; border-color: #d7dce7; }
.icon-btn:active { transform: translateY(1px); }

/* ---------------- 成员面板 ---------------- */
.panel {
  position: fixed;
  top: 68px; left: 12px;
  width: 306px;
  max-height: calc(100vh - 92px);
  display: flex; flex-direction: column;
  background: var(--card);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  border: 1px solid var(--line);
  z-index: 1100;
  overflow: hidden;
}

.panel-head {
  display: flex; align-items: center; justify-content: space-between;
  padding: 12px 14px 10px;
  font-size: 12.5px; color: var(--sub);
  border-bottom: 1px solid var(--line);
}
.panel-head b { color: var(--text); }

.link-btn {
  border: 0; background: none; color: var(--brand);
  font-size: 12.5px; cursor: pointer; padding: 2px 0;
}

.member-list { overflow-y: auto; padding: 6px; }
.member-list::-webkit-scrollbar { width: 6px; }
.member-list::-webkit-scrollbar-thumb { background: #dfe4ee; border-radius: 3px; }

.member {
  display: flex; align-items: center; gap: 10px;
  padding: 10px 10px;
  border-radius: 11px;
  cursor: pointer;
  transition: background .15s;
}
.member:hover { background: #f7f9fd; }
.member.active { background: var(--brand-soft); }
.member.stale { opacity: .62; }

.avatar {
  width: 34px; height: 34px; flex: none;
  border-radius: 50%;
  display: grid; place-items: center;
  color: #fff; font-size: 13px; font-weight: 600;
  position: relative;
}
.avatar::after {
  content: "";
  position: absolute; right: -1px; bottom: -1px;
  width: 10px; height: 10px; border-radius: 50%;
  border: 2px solid #fff;
  background: #c2c8d4;
}
.member.online .avatar::after { background: var(--ok); }

.m-main { flex: 1; min-width: 0; }
.m-name {
  font-size: 13.5px; font-weight: 600;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.m-sub {
  font-size: 11.5px; color: var(--sub); margin-top: 3px;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.m-batt { font-size: 11.5px; color: var(--sub); flex: none; display: flex; align-items: center; gap: 3px; }
.batt-bar {
  width: 20px; height: 9px; border: 1.5px solid #c9cfdb; border-radius: 3px;
  position: relative; display: inline-block;
}
.batt-bar::before {
  content: ""; position: absolute; left: 1px; top: 1px; bottom: 1px;
  width: var(--lv, 60%); border-radius: 1px; background: var(--ok);
}
.batt-bar.low::before { background: var(--bad); }
.batt-bar.mid::before { background: var(--warn); }

.empty {
  padding: 16px 14px 20px;
  font-size: 12px; line-height: 1.7; color: var(--sub);
}

/* ---------------- 轨迹条 ---------------- */
.trackbar {
  position: fixed;
  bottom: 16px; left: 50%;
  transform: translate(-50%, 20px);
  width: min(560px, calc(100vw - 24px));
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 12px 14px;
  z-index: 1150;
  opacity: 0;
  pointer-events: none;
  transition: .22s;
}
.trackbar.show { opacity: 1; transform: translate(-50%, 0); pointer-events: auto; }

.track-info { display: flex; align-items: center; gap: 8px; font-size: 13px; }
.track-info .dot { width: 9px; height: 9px; border-radius: 50%; background: var(--brand); }
.muted { color: var(--sub); }
.track-actions {
  display: flex; align-items: center; justify-content: space-between;
  margin-top: 10px; gap: 10px; flex-wrap: wrap;
}

.seg { display: inline-flex; background: #f2f4f8; border-radius: 9px; padding: 3px; }
.seg button {
  border: 0; background: none; font-size: 12.5px; color: var(--sub);
  padding: 5px 12px; border-radius: 7px; cursor: pointer;
}
.seg button.active { background: #fff; color: var(--text); box-shadow: 0 1px 3px rgba(16,24,40,.12); }

.track-tip { font-size: 11.5px; color: var(--sub); margin-top: 8px; }

/* ---------------- 登录 ---------------- */
.mask {
  position: fixed; inset: 0;
  background: rgba(16, 24, 40, 0.42);
  backdrop-filter: blur(3px);
  display: grid; place-items: center;
  padding: 18px;
  z-index: 3000;
}
.mask[hidden] { display: none; }

.auth-card {
  width: 100%; max-width: 380px;
  background: #fff;
  border-radius: 18px;
  padding: 26px 24px 20px;
  box-shadow: 0 24px 60px rgba(16, 24, 40, .22);
}
.auth-head { text-align: center; margin-bottom: 18px; }
.auth-head h1 { font-size: 19px; margin: 12px 0 6px; }
.auth-head p { font-size: 12px; color: var(--sub); line-height: 1.6; margin: 0; }

.tabs {
  display: flex; gap: 4px; background: #f2f4f8;
  padding: 4px; border-radius: 10px; margin-bottom: 16px;
}
.tabs button {
  flex: 1; border: 0; background: none; padding: 8px;
  font-size: 13px; color: var(--sub); border-radius: 7px; cursor: pointer;
}
.tabs button.active { background: #fff; color: var(--text); font-weight: 600; box-shadow: 0 1px 3px rgba(16,24,40,.1); }

.field { display: block; margin-bottom: 12px; }
.field span { display: block; font-size: 12px; color: var(--sub); margin-bottom: 6px; }
.field input {
  width: 100%; padding: 11px 12px;
  border: 1px solid var(--line); border-radius: 10px;
  font-size: 14px; color: var(--text); background: #fbfcfe;
  outline: none; transition: .15s;
}
.field input:focus { border-color: var(--brand); background: #fff; box-shadow: 0 0 0 3px var(--brand-soft); }

.primary {
  width: 100%; border: 0; border-radius: 10px;
  background: var(--brand); color: #fff;
  font-size: 14px; font-weight: 600; padding: 12px;
  cursor: pointer; transition: .15s;
}
.primary:hover { filter: brightness(1.05); }
.primary:active { transform: translateY(1px); }
.primary[disabled] { opacity: .6; cursor: default; }

.ghost {
  width: 100%; border: 1px solid var(--line); border-radius: 10px;
  background: #fff; color: var(--text); font-size: 14px; padding: 11px; cursor: pointer;
}

.auth-msg { min-height: 16px; font-size: 12px; color: var(--bad); margin: 10px 0 0; }
.auth-foot { font-size: 11px; color: #98a2b3; line-height: 1.7; text-align: center; margin: 14px 0 0; }

/* ---------------- 邀请 ---------------- */
.invite-card {
  width: 100%; max-width: 360px; background: #fff;
  border-radius: 18px; padding: 24px; box-shadow: 0 24px 60px rgba(16,24,40,.22);
}
.invite-card h2 { font-size: 17px; margin: 0 0 8px; }
.invite-card p { font-size: 12.5px; line-height: 1.7; }
.code {
  font: 600 26px/1.2 ui-monospace, SFMono-Regular, Menlo, monospace;
  letter-spacing: 6px; text-align: center;
  background: var(--brand-soft); color: var(--brand);
  border-radius: 12px; padding: 16px 10px; margin: 16px 0;
}
.invite-row { display: flex; gap: 10px; }
.invite-row .primary, .invite-row .ghost { width: auto; flex: 1; }
.small { font-size: 11px !important; color: #98a2b3; }

/* ---------------- 地图标记 ---------------- */
.pin {
  width: 34px; height: 34px; border-radius: 50%;
  border: 3px solid #fff;
  box-shadow: 0 3px 12px rgba(16,24,40,.32);
  display: grid; place-items: center;
  color: #fff; font-size: 12px; font-weight: 700;
}
.pin.me { outline: 3px solid rgba(47,111,237,.22); }
.leaflet-control-zoom { border: 1px solid var(--line) !important; border-radius: 10px !important; overflow: hidden; }
.leaflet-control-attribution { font-size: 10px; background: rgba(255,255,255,.78) !important; }
.leaflet-popup-content-wrapper { border-radius: 12px; }

/* ---------------- toast ---------------- */
.toast {
  position: fixed; left: 50%; bottom: 96px;
  transform: translate(-50%, 12px);
  background: rgba(16,24,40,.92); color: #fff;
  font-size: 13px; padding: 10px 16px; border-radius: 10px;
  opacity: 0; pointer-events: none; transition: .22s;
  z-index: 4000; max-width: 84vw; text-align: center;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }

/* ---------------- 移动端 ---------------- */
@media (max-width: 720px) {
  .topbar { height: 54px; padding: 0 10px; gap: 6px; }
  .brand-text small { display: none; }
  .brand { gap: 8px; min-width: 0; }
  .brand-text strong { font-size: 14px; white-space: nowrap; }
  .live { display: none; }
  .topbar-right { gap: 6px; flex: none; }
  .icon-btn { padding: 6px 9px; font-size: 12px; white-space: nowrap; }

  .panel {
    top: auto; bottom: 0; left: 0; right: 0;
    width: 100%; max-height: 42vh;
    border-radius: 16px 16px 0 0;
    border-left: 0; border-right: 0; border-bottom: 0;
    padding-bottom: env(safe-area-inset-bottom);
  }
  .member-list { max-height: 30vh; }
  .trackbar { bottom: calc(42vh + 10px); width: calc(100vw - 20px); }
  .leaflet-control-zoom { display: none; }
}

@media (max-width: 400px) {
  .icon-btn { padding: 6px 7px; font-size: 11.5px; }
  .brand-text strong { font-size: 13px; }
}
