* { box-sizing: border-box; margin: 0; padding: 0; }
html, body { height: 100%; overflow: hidden; }
body {
  font-family: -apple-system, "PingFang SC", "Microsoft YaHei", sans-serif;
  color: #1f2937;
  background: #f3f4f6;
}
.hidden { display: none !important; }

/* ---------- 登录页 ---------- */
.login-wrap {
  height: 100vh;
  overflow: auto;
  display: flex;
  align-items: center;
  justify-content: center;
  background: linear-gradient(135deg, #1e3a8a 0%, #2563eb 55%, #38bdf8 100%);
}
.login-card {
  width: 360px;
  max-width: calc(100vw - 32px);
  background: #fff;
  border-radius: 16px;
  padding: 40px 32px;
  box-shadow: 0 24px 60px rgba(15, 23, 42, .35);
  text-align: center;
}
.login-logo { font-size: 44px; }
.login-card h1 { font-size: 22px; margin: 12px 0 4px; }
.login-sub { font-size: 13px; color: #6b7280; margin-bottom: 24px; }
.login-card input {
  width: 100%;
  padding: 12px 14px;
  margin-bottom: 12px;
  border: 1px solid #d1d5db;
  border-radius: 10px;
  font-size: 15px;
  outline: none;
  transition: border-color .15s;
}
.login-card input:focus { border-color: #2563eb; }
.login-card button[type="submit"] {
  width: 100%;
  padding: 12px;
  border: none;
  border-radius: 10px;
  background: #2563eb;
  color: #fff;
  font-size: 16px;
  cursor: pointer;
  transition: background .15s;
}
.login-card button[type="submit"]:hover { background: #1d4ed8; }
.login-card button[type="submit"]:disabled { background: #93c5fd; cursor: wait; }
.login-error { color: #dc2626; font-size: 13px; margin-top: 10px; min-height: 18px; }

/* ---------- 主界面 ---------- */
.main-wrap { height: 100vh; display: flex; flex-direction: column; overflow: hidden; }
.topbar {
  height: 56px;
  flex: none;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 20px;
  background: #111827;
  color: #fff;
}
.brand { font-weight: 600; font-size: 16px; }
.topbar-right { display: flex; align-items: center; gap: 12px; font-size: 14px; }
.ghost-btn {
  padding: 6px 14px;
  border: 1px solid #d1d5db;
  border-radius: 8px;
  background: transparent;
  color: inherit;
  font-size: 13px;
  cursor: pointer;
}
.topbar .ghost-btn { border-color: #4b5563; }
.ghost-btn:hover { background: rgba(148, 163, 184, .15); }
.ghost-btn.full { width: 100%; margin-top: 10px; color: #2563eb; border-color: #bfdbfe; }

.content { flex: 1; display: flex; min-height: 0; overflow: hidden; }
.map-area {
  flex: 1;
  position: relative;
  min-width: 0;
  min-height: 0;
  overflow: hidden;
}
.sidebar {
  width: 300px;
  flex: none;
  overflow-y: auto;
  background: #fff;
  border-right: 1px solid #e5e7eb;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 16px;
}
#map {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
}

.map-switch {
  position: absolute;
  top: 12px;
  right: 12px;
  z-index: 1000;
  display: flex;
  background: #fff;
  border-radius: 8px;
  box-shadow: 0 2px 10px rgba(0, 0, 0, .25);
  overflow: hidden;
}
.map-switch button {
  border: none;
  background: #fff;
  padding: 8px 14px;
  font-size: 13px;
  cursor: pointer;
  color: #374151;
}
.map-switch button + button { border-left: 1px solid #e5e7eb; }
.map-switch button:hover { background: #f3f4f6; }
.map-switch button.active {
  background: #2563eb;
  color: #fff;
}

.panel h2 { font-size: 14px; color: #374151; margin-bottom: 10px; }
.panel .hint { font-weight: 400; font-size: 12px; color: #9ca3af; }

.device-item {
  border: 1px solid #e5e7eb;
  border-radius: 10px;
  padding: 10px 12px;
  margin-bottom: 8px;
  cursor: pointer;
  transition: border-color .15s, background .15s;
}
.device-item:hover { border-color: #93c5fd; }
.device-item.active { border-color: #2563eb; background: #eff6ff; }
.device-name { font-weight: 600; font-size: 14px; }
.device-meta { font-size: 12px; color: #6b7280; margin-top: 4px; line-height: 1.5; }
.device-meta .stale { color: #d97706; }
.device-meta .fresh { color: #059669; }

.day-list { display: flex; flex-wrap: wrap; gap: 6px; }
.day-chip {
  padding: 5px 10px;
  border: 1px solid #e5e7eb;
  border-radius: 999px;
  font-size: 12px;
  cursor: pointer;
  background: #f9fafb;
}
.day-chip:hover { border-color: #93c5fd; }
.day-chip.active { background: #2563eb; border-color: #2563eb; color: #fff; }
.day-empty { font-size: 12px; color: #9ca3af; }

.track-filter {
  margin-top: 10px;
  border: 1px solid #e5e7eb;
  border-radius: 8px;
  font-size: 12px;
}
.track-filter summary {
  padding: 8px 10px;
  cursor: pointer;
  color: #374151;
  font-weight: 500;
  user-select: none;
}
.track-filter-body {
  padding: 0 10px 10px;
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.track-filter-body input[type="range"] { width: 100%; }
.track-filter-body .hint { font-weight: 400; color: #9ca3af; }

.status-panel { margin-top: auto; }
#live-status { font-size: 12px; color: #6b7280; }

.marker-label {
  background: #2563eb;
  color: #fff;
  border: 2px solid #fff;
  border-radius: 50%;
  width: 34px !important;
  height: 34px !important;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 16px;
  box-shadow: 0 2px 8px rgba(0, 0, 0, .35);
}

.replay-marker {
  font-size: 24px;
  line-height: 32px;
  text-align: center;
}

.track-arrow-wrap {
  background: transparent !important;
  border: none !important;
}
.track-arrow {
  display: flex;
  align-items: center;
  justify-content: center;
  transform-origin: center center;
  filter: drop-shadow(0 0 1px #fff) drop-shadow(0 0 2px #fff);
  pointer-events: none;
  user-select: none;
}

.replay-bar {
  position: absolute;
  left: 12px;
  right: 12px;
  bottom: 12px;
  z-index: 1000;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 14px;
  background: rgba(255, 255, 255, 0.96);
  border-radius: 12px;
  box-shadow: 0 4px 20px rgba(0, 0, 0, .2);
}
.replay-play-btn {
  width: 36px;
  height: 36px;
  border: none;
  border-radius: 50%;
  background: #2563eb;
  color: #fff;
  font-size: 14px;
  cursor: pointer;
  flex: none;
}
.replay-play-btn:hover { background: #1d4ed8; }
.replay-time {
  font-size: 12px;
  color: #374151;
  font-variant-numeric: tabular-nums;
  flex: none;
  min-width: 64px;
}
.replay-slider {
  flex: 1;
  height: 6px;
  accent-color: #2563eb;
  cursor: pointer;
}
.replay-speed {
  border: 1px solid #d1d5db;
  border-radius: 6px;
  padding: 4px 6px;
  font-size: 12px;
  flex: none;
}

/* 电子围栏 */
.fence-list { margin-bottom: 8px; }
.fence-item {
  border: 1px solid #fde68a;
  background: #fffbeb;
  border-radius: 8px;
  padding: 8px 10px;
  margin-bottom: 6px;
  font-size: 13px;
}
.fence-item-name { font-weight: 600; }
.fence-radius { color: #b45309; font-size: 12px; font-weight: 400; }
.fence-item-meta { font-size: 11px; color: #92400e; margin-top: 2px; }
.fence-del {
  margin-top: 6px;
  border: 1px solid #fecaca;
  background: #fff;
  color: #dc2626;
  font-size: 11px;
  padding: 2px 8px;
  border-radius: 4px;
  cursor: pointer;
}
.fence-form {
  border: 1px dashed #93c5fd;
  border-radius: 8px;
  padding: 10px;
  margin-bottom: 8px;
  background: #eff6ff;
}
.fence-form input[type="text"] {
  width: 100%;
  padding: 6px 8px;
  border: 1px solid #d1d5db;
  border-radius: 6px;
  margin-bottom: 8px;
}
.fence-label { font-size: 12px; color: #374151; }
.fence-form input[type="range"] { width: 100%; margin: 4px 0 8px; }
.fence-check { display: block; font-size: 12px; margin-bottom: 4px; }
.fence-hint { font-size: 11px; color: #6b7280; margin: 6px 0; }
.fence-form-btns { display: flex; gap: 8px; }
.fence-form-btns button:first-child {
  flex: 1;
  padding: 8px;
  border: none;
  border-radius: 6px;
  background: #2563eb;
  color: #fff;
  cursor: pointer;
}
.fence-form-btns button:first-child:disabled { background: #93c5fd; cursor: wait; }
.fence-pin { font-size: 22px; text-align: center; }

/* 通知 */
.topbar-right { position: relative; }
.notify-btn {
  position: relative;
  border: none;
  background: transparent;
  font-size: 18px;
  cursor: pointer;
  padding: 4px 8px;
}
.notify-badge {
  position: absolute;
  top: 0;
  right: 2px;
  background: #dc2626;
  color: #fff;
  font-size: 10px;
  min-width: 16px;
  height: 16px;
  line-height: 16px;
  text-align: center;
  border-radius: 8px;
  padding: 0 4px;
}
.notify-panel {
  position: absolute;
  top: 48px;
  right: 16px;
  width: 320px;
  max-height: 400px;
  overflow-y: auto;
  background: #fff;
  border-radius: 12px;
  box-shadow: 0 8px 30px rgba(0,0,0,.2);
  z-index: 2000;
  padding: 8px 0;
}
.notify-item { padding: 10px 14px; border-bottom: 1px solid #f3f4f6; }
.notify-item.unread { background: #eff6ff; }
.notify-title { font-weight: 600; font-size: 13px; }
.notify-body { font-size: 12px; color: #4b5563; margin-top: 4px; line-height: 1.4; }
.notify-time { font-size: 11px; color: #9ca3af; margin-top: 4px; }
.notify-empty { padding: 20px; text-align: center; color: #9ca3af; font-size: 13px; }
.notify-read-all {
  display: block;
  width: calc(100% - 24px);
  margin: 8px 12px;
  padding: 8px;
  border: 1px solid #e5e7eb;
  background: #f9fafb;
  border-radius: 6px;
  cursor: pointer;
  font-size: 12px;
}

@media (max-width: 760px) {
  .content { flex-direction: column; }
  .sidebar { width: 100%; max-height: 45%; border-right: none; border-bottom: 1px solid #e5e7eb; }
}
