:root {
  --bg: #0f172a;
  --bg-elevated: #1e293b;
  --border: #334155;
  --text: #f1f5f9;
  --text-muted: #94a3b8;
  --accent: #38bdf8;
  --live: #22c55e;
  --danger: #f43f5e;
  --radius: 12px;
  --font: 'Segoe UI', system-ui, -apple-system, sans-serif;
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  height: 100%;
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
}

.app {
  display: flex;
  flex-direction: column;
  height: 100vh;
  overflow: hidden;
}

.top-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.75rem 1.25rem;
  background: var(--bg-elevated);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
  z-index: 1000;
}

.brand {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-weight: 700;
  letter-spacing: 0.02em;
}

.logo-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--accent), #818cf8);
  box-shadow: 0 0 12px rgba(56, 189, 248, 0.6);
}

.brand-name {
  font-size: 1.1rem;
}

.top-bar-right {
  display: flex;
  align-items: center;
  gap: 1rem;
}

.guest-msg {
  color: var(--text-muted);
  font-size: 0.9rem;
}

.user-chip {
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

.user-chip img {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  border: 2px solid var(--live);
  object-fit: cover;
  background: var(--bg);
}

.user-chip.hidden,
.hidden {
  display: none !important;
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0.45rem 1rem;
  border-radius: 999px;
  font-size: 0.875rem;
  font-weight: 600;
  border: 1px solid transparent;
  cursor: pointer;
  text-decoration: none;
  transition: background 0.15s, border-color 0.15s, color 0.15s;
}

.btn-primary {
  background: linear-gradient(135deg, #2563eb, #7c3aed);
  color: #fff;
}

.btn-primary:hover {
  filter: brightness(1.08);
}

.btn-ghost {
  background: transparent;
  color: var(--text-muted);
  border-color: var(--border);
}

.btn-ghost:hover {
  color: var(--text);
  border-color: var(--text-muted);
}

.main {
  display: flex;
  flex: 1;
  min-height: 0;
}

.sidebar {
  width: 300px;
  flex-shrink: 0;
  background: var(--bg-elevated);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  padding: 1rem;
  gap: 0.5rem;
}

.sidebar-section h2,
.sidebar-section h3 {
  margin: 0 0 0.5rem;
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-muted);
}

.sidebar-section.grow {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
}

.stat {
  margin: 0;
  display: flex;
  align-items: baseline;
  gap: 0.35rem;
}

.stat-value {
  font-size: 1.75rem;
  font-weight: 700;
  color: var(--accent);
}

.stat-label {
  font-size: 0.85rem;
  color: var(--text-muted);
}

.user-list {
  list-style: none;
  margin: 0;
  padding: 0;
  overflow-y: auto;
  flex: 1;
}

.user-row {
  display: flex;
  align-items: center;
  gap: 0.65rem;
  padding: 0.5rem 0.35rem;
  border-radius: var(--radius);
  margin-bottom: 0.25rem;
}

.user-row:hover {
  background: rgba(255, 255, 255, 0.04);
}

.user-row.offline {
  opacity: 0.55;
}

.user-row-avatar {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  object-fit: cover;
  border: 2px solid var(--live);
  background: var(--bg);
}

.user-row.offline .user-row-avatar {
  border-color: var(--text-muted);
}

.user-row-meta {
  display: flex;
  flex-direction: column;
  gap: 0.15rem;
  min-width: 0;
}

.user-row-name {
  font-size: 0.9rem;
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.user-row-badge {
  font-size: 0.7rem;
  color: var(--live);
}

.user-row.offline .user-row-badge {
  color: var(--text-muted);
}

.empty-hint {
  font-size: 0.85rem;
  color: var(--text-muted);
  margin: 0.5rem 0 0;
}

.legend-list {
  list-style: none;
  margin: 0;
  padding: 0;
  font-size: 0.85rem;
  color: var(--text-muted);
}

.legend-list li {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  margin-bottom: 0.35rem;
}

.dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
}

.dot-live {
  background: var(--live);
  box-shadow: 0 0 8px rgba(34, 197, 94, 0.7);
}

.dot-away {
  background: var(--text-muted);
}

.map-wrap {
  flex: 1;
  position: relative;
  min-width: 0;
}

#map {
  width: 100%;
  height: 100%;
}

.geo-warning {
  position: absolute;
  bottom: 1rem;
  left: 50%;
  transform: translateX(-50%);
  z-index: 800;
  margin: 0;
  padding: 0.5rem 1rem;
  background: rgba(15, 23, 42, 0.92);
  border: 1px solid var(--danger);
  border-radius: var(--radius);
  color: #fecdd3;
  font-size: 0.85rem;
  max-width: 90%;
  text-align: center;
}

.user-marker {
  display: flex;
  flex-direction: column;
  align-items: center;
  filter: drop-shadow(0 2px 4px rgba(0, 0, 0, 0.4));
}

.avatar-wrap {
  position: relative;
  width: 40px;
  height: 40px;
}

.user-marker img {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  border: 3px solid #22c55e;
  background: #1e293b;
  object-fit: cover;
  display: block;
}

.user-marker span:not(.pulse-dot) {
  background: rgba(0, 0, 0, 0.75);
  color: white;
  font-size: 11px;
  padding: 2px 6px;
  border-radius: 10px;
  margin-top: 2px;
  white-space: nowrap;
}

.pulse-dot {
  position: absolute;
  bottom: -2px;
  right: -2px;
  width: 12px;
  height: 12px;
  border-radius: 50%;
  background: #22c55e;
  border: 2px solid #0f172a;
  animation: pulse 2s ease-out infinite;
}

@keyframes pulse {
  0% {
    box-shadow: 0 0 0 0 rgba(34, 197, 94, 0.7);
  }
  70% {
    box-shadow: 0 0 0 10px rgba(34, 197, 94, 0);
  }
  100% {
    box-shadow: 0 0 0 0 rgba(34, 197, 94, 0);
  }
}

.leaflet-container {
  background: #0b1220;
  font-family: var(--font);
}

.leaflet-control-attribution {
  background: rgba(15, 23, 42, 0.75) !important;
  color: var(--text-muted) !important;
  font-size: 10px !important;
  border-radius: 6px 0 0 0 !important;
  padding: 2px 6px !important;
}

.leaflet-control-attribution a {
  color: var(--accent) !important;
}

.leaflet-popup-content-wrapper {
  border-radius: var(--radius);
  background: var(--bg-elevated);
  color: var(--text);
}

.leaflet-popup-tip {
  background: var(--bg-elevated);
}

@media (max-width: 900px) {
  .sidebar {
    width: 260px;
  }
}

@media (max-width: 720px) {
  .main {
    flex-direction: column;
  }

  .sidebar {
    width: 100%;
    max-height: 40vh;
    border-right: none;
    border-bottom: 1px solid var(--border);
  }

  .map-wrap {
    min-height: 50vh;
  }
}
