:root {
  --bg: #0b1120;
  --surface: rgba(15, 23, 42, 0.94);
  --surface-2: #1e293b;
  --border: rgba(148, 163, 184, 0.16);
  --text: #f8fafc;
  --muted: #94a3b8;
  --accent: #3b82f6;
  --green: #10b981;
  --amber: #f59e0b;
  --red: #ef4444;
  --radius: 14px;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", Roboto, sans-serif;
  -webkit-font-smoothing: antialiased;
}

.hidden { display: none !important; }

/* Auth / Onboarding */
.auth-screen {
  min-height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  background: radial-gradient(circle at top, #172554 0%, #0b1120 65%);
}

.auth-card {
  width: 100%;
  max-width: 420px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 20px;
  padding: 28px;
  box-shadow: 0 24px 60px rgba(0, 0, 0, 0.45);
}

.brand { display: flex; align-items: center; gap: 12px; margin-bottom: 18px; }
.brand-icon {
  width: 44px; height: 44px; border-radius: 12px;
  background: linear-gradient(135deg, #3b82f6, #8b5cf6);
  display: grid; place-items: center; font-size: 22px;
}
.brand h1 { margin: 0; font-size: 22px; font-weight: 700; }
.brand p { margin: 2px 0 0; color: var(--muted); font-size: 13px; }

.tabs {
  display: grid; grid-template-columns: 1fr 1fr; gap: 6px;
  background: rgba(15, 23, 42, 0.8); padding: 4px;
  border-radius: 12px; border: 1px solid var(--border); margin-bottom: 18px;
}
.tab-btn {
  border: none; background: transparent; color: var(--muted);
  padding: 9px 12px; border-radius: 9px; font-weight: 600; font-size: 14px; cursor: pointer;
}
.tab-btn.active { background: var(--surface-2); color: var(--text); }

.field { margin-bottom: 14px; }
.field label { display: block; font-size: 12px; font-weight: 600; color: var(--muted); margin-bottom: 6px; }
.field input, .field select {
  width: 100%; padding: 11px 13px; border-radius: 10px;
  border: 1px solid var(--border); background: #0f172a; color: var(--text); font-size: 15px; outline: none;
}
.field input:focus { border-color: var(--accent); }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  border: none; border-radius: 11px; padding: 10px 14px;
  font-weight: 600; font-size: 13px; cursor: pointer; transition: opacity 0.15s ease;
}
.btn:hover { opacity: 0.92; }
.btn-primary { background: var(--accent); color: #fff; width: 100%; }
.btn-secondary { background: var(--surface-2); color: var(--text); border: 1px solid var(--border); }
.btn-success { background: rgba(16, 185, 129, 0.2); color: #6ee7b7; border: 1px solid rgba(16, 185, 129, 0.4); }
.btn-danger { background: rgba(239, 68, 68, 0.18); color: #fca5a5; border: 1px solid rgba(239, 68, 68, 0.45); }
.btn-sos { background: #dc2626; color: #fff; font-weight: 700; }
.btn-sm { padding: 7px 10px; font-size: 12px; border-radius: 8px; }

.error-banner {
  background: rgba(239, 68, 68, 0.16); border: 1px solid rgba(239, 68, 68, 0.4);
  color: #fecaca; padding: 10px 12px; border-radius: 10px; font-size: 13px; margin-bottom: 14px;
}

/* Main Dashboard */
.app-layout {
  display: grid;
  grid-template-columns: 375px 1fr;
  height: 100vh;
  overflow: hidden;
}

.sidebar {
  background: var(--surface);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  height: 100%;
  overflow: hidden;
  z-index: 10;
}

.sidebar-header {
  padding: 15px 18px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}
.circle-title { margin: 0; font-size: 17px; font-weight: 700; }

.live-pill {
  display: inline-flex; align-items: center; gap: 6px;
  font-size: 11px; font-weight: 600; color: var(--green);
  background: rgba(16, 185, 129, 0.12); padding: 4px 9px; border-radius: 999px;
}
.live-dot { width: 7px; height: 7px; border-radius: 50%; background: var(--green); }

.nav-pills {
  display: grid; grid-template-columns: repeat(3, 1fr); gap: 6px;
  padding: 10px 16px; border-bottom: 1px solid var(--border);
}
.nav-pill {
  border: 1px solid transparent; background: transparent; color: var(--muted);
  padding: 8px 6px; border-radius: 10px; font-weight: 600; font-size: 13px; cursor: pointer;
}
.nav-pill.active { background: var(--surface-2); color: var(--text); border-color: var(--border); }

.panel-scroll { flex: 1; overflow-y: auto; padding: 14px 16px; }

.card-item {
  background: rgba(30, 41, 59, 0.55);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 12px 14px;
  margin-bottom: 10px;
  cursor: pointer;
  transition: border-color 0.15s ease;
}
.card-item:hover { border-color: rgba(59, 130, 246, 0.55); }
.card-item.sos-card { border-color: rgba(239, 68, 68, 0.65); background: rgba(127, 29, 29, 0.35); }

.member-row { display: flex; align-items: center; gap: 12px; }
.avatar {
  width: 44px; height: 44px; border-radius: 50%;
  display: grid; place-items: center; font-size: 20px; flex-shrink: 0;
  border: 2px solid rgba(255, 255, 255, 0.25); overflow: hidden;
}
.avatar img { width: 100%; height: 100%; object-fit: cover; display: block; }

.member-info { flex: 1; min-width: 0; }
.member-name { font-weight: 700; font-size: 15px; display: flex; align-items: center; gap: 6px; flex-wrap: wrap; }
.member-meta { font-size: 12px; color: var(--muted); margin-top: 3px; }
.badges-row { display: flex; flex-wrap: wrap; gap: 5px; margin-top: 6px; align-items: center; }

.battery-badge {
  font-size: 12px; font-weight: 600; padding: 4px 8px; border-radius: 999px;
  background: rgba(15, 23, 42, 0.8); border: 1px solid var(--border); white-space: nowrap;
}
.battery-low { color: var(--red); }
.battery-mid { color: var(--amber); }
.battery-ok { color: var(--green); }

.place-badge, .motion-badge {
  display: inline-flex; align-items: center; gap: 4px;
  font-size: 11px; font-weight: 600; padding: 3px 8px; border-radius: 999px;
}
.place-badge { background: rgba(59, 130, 246, 0.16); color: #93c5fd; }
.motion-driving { background: rgba(139, 92, 246, 0.22); color: #c4b5fd; }
.motion-walking { background: rgba(16, 185, 129, 0.18); color: #6ee7b7; }

.member-actions { display: flex; gap: 6px; margin-top: 10px; }

.sidebar-footer {
  padding: 12px 16px;
  border-top: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.invite-box {
  display: flex; align-items: center; justify-content: space-between;
  background: #0f172a; border: 1px solid var(--border);
  border-radius: 10px; padding: 7px 11px; font-size: 12px;
}
.invite-code {
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-weight: 700; color: #93c5fd; letter-spacing: 0.5px;
}

.action-row { display: flex; gap: 6px; }

.map-wrap { position: relative; width: 100%; height: 100%; background: #0f172a; }
#map { width: 100%; height: 100%; }

.sos-banner {
  position: absolute; top: 14px; left: 50%; transform: translateX(-50%);
  z-index: 600; width: min(92%, 520px);
  background: rgba(185, 28, 28, 0.96);
  border: 2px solid #fca5a5;
  color: #fff;
  padding: 12px 16px;
  border-radius: 14px;
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  box-shadow: 0 12px 32px rgba(220, 38, 38, 0.55);
}

.route-banner {
  position: absolute; bottom: 18px; left: 50%; transform: translateX(-50%);
  z-index: 550; width: min(92%, 480px);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 12px 15px;
  display: flex; align-items: center; justify-content: space-between; gap: 10px;
  box-shadow: 0 10px 28px rgba(0, 0, 0, 0.45);
}

.map-hint {
  position: absolute; top: 14px; left: 50%; transform: translateX(-50%);
  z-index: 500; background: var(--surface); border: 1px solid var(--border);
  padding: 8px 14px; border-radius: 999px; font-size: 13px; color: var(--text);
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.35);
}

.marker-pin { display: flex; flex-direction: column; align-items: center; }
.marker-bubble {
  width: 42px; height: 42px; border-radius: 50%;
  display: grid; place-items: center; font-size: 20px;
  border: 3px solid #fff; box-shadow: 0 6px 16px rgba(0, 0, 0, 0.45); overflow: hidden;
}
.marker-bubble img { width: 100%; height: 100%; object-fit: cover; display: block; }
.marker-label {
  margin-top: 3px; background: rgba(15, 23, 42, 0.92); color: #fff;
  font-size: 11px; font-weight: 700; padding: 2px 7px; border-radius: 999px;
  white-space: nowrap; border: 1px solid rgba(255, 255, 255, 0.2);
}

.event-row { display: flex; align-items: flex-start; gap: 10px; }
.event-icon { font-size: 18px; margin-top: 1px; }
.empty-state { text-align: center; color: var(--muted); padding: 28px 12px; font-size: 13px; }
.form-box {
  background: rgba(15, 23, 42, 0.7); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 12px; margin-bottom: 12px;
}
.row-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }

@media (max-width: 820px) {
  .app-layout { grid-template-columns: 1fr; grid-template-rows: 52vh 48vh; }
  .sidebar { order: 2; border-right: none; border-top: 1px solid var(--border); }
  .map-wrap { order: 1; }
}
