:root {
  --bg-main: #f8fafc;
  --bg-surface: #ffffff;
  --bg-surface-elevated: #f1f5f9;
  --bg-glass: rgba(255, 255, 255, 0.92);
  --border-color: rgba(0, 0, 0, 0.08);
  --border-focus: #4f46e5;

  --primary: #4f46e5;
  --primary-hover: #4338ca;
  --primary-glow: rgba(79, 70, 229, 0.25);

  --success: #10b981;
  --success-glow: rgba(16, 185, 129, 0.25);

  --warning: #f59e0b;
  --danger: #ef4444;
  --danger-glow: rgba(239, 68, 68, 0.35);
  --purple: #8b5cf6;

  --text-main: #0f172a;
  --text-muted: #475569;
  --text-dim: #94a3b8;

  --font-family: 'Plus Jakarta Sans', system-ui, -apple-system, sans-serif;
  --radius-sm: 8px;
  --radius-md: 14px;
  --radius-lg: 20px;
  --radius-full: 9999px;

  --shadow-sm: 0 2px 8px rgba(0, 0, 0, 0.25);
  --shadow-md: 0 8px 24px rgba(0, 0, 0, 0.35);
  --shadow-lg: 0 16px 40px rgba(0, 0, 0, 0.5);
}

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

body {
  background: linear-gradient(135deg, #eef2ff 0%, #f1f5f9 50%, #e2e8f0 100%);
  color: var(--text-main);
  font-family: var(--font-family);
  display: flex;
  justify-content: center;
  align-items: center;
  min-height: 100vh;
  overflow: hidden;
}

/* App Container (Phone Mockup on desktop, full screen on mobile) */
.app-container {
  width: 100%;
  max-width: 440px;
  height: 100vh;
  max-height: 900px;
  background: var(--bg-main);
  position: relative;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  box-shadow: 0 25px 60px -15px rgba(0, 0, 0, 0.15), 0 0 0 1px rgba(0, 0, 0, 0.05);
  border-radius: 0;
}

@media (min-width: 480px) {
  .app-container {
    height: 92vh;
    border-radius: 36px;
    border: 8px solid #0f172a;
    box-shadow: 0 30px 70px -10px rgba(15, 23, 42, 0.25), 0 0 0 1px rgba(0, 0, 0, 0.08);
  }
}


/* Header */
.app-header {
  height: 60px;
  padding: 0 18px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  background: var(--bg-glass);
  backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--border-color);
  z-index: 1000;
}

.logo-badge {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 1.15rem;
  font-weight: 800;
  letter-spacing: -0.5px;
}

.logo-badge i {
  font-size: 1.35rem;
  color: var(--primary);
}

.header-right {
  display: flex;
  gap: 8px;
}

.header-action-btn {
  width: 38px;
  height: 38px;
  border-radius: var(--radius-full);
  background: var(--bg-surface);
  border: 1px solid var(--border-color);
  display: flex;
  justify-content: center;
  align-items: center;
  color: var(--text-main);
  cursor: pointer;
  position: relative;
  transition: all 0.2s ease;
}

.header-action-btn:hover {
  background: var(--bg-surface-elevated);
}

#headerSosBtn {
  background: rgba(239, 68, 68, 0.15);
  border-color: rgba(239, 68, 68, 0.3);
  color: var(--danger);
}

.notif-badge {
  position: absolute;
  top: -2px;
  right: -2px;
  background: var(--danger);
  color: #fff;
  font-size: 10px;
  font-weight: 700;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  display: flex;
  justify-content: center;
  align-items: center;
}

/* Content Area */
.app-content {
  flex: 1;
  position: relative;
  overflow-y: auto;
  overflow-x: hidden;
}

.view-screen {
  width: 100%;
  height: 100%;
  display: flex;
  flex-direction: column;
}

/* Auth Card */
.auth-card {
  padding: 30px 24px;
  display: flex;
  flex-direction: column;
  justify-content: center;
  min-height: 100%;
}

.auth-hero {
  text-align: center;
  margin-bottom: 28px;
}

.auth-icon-ring {
  width: 72px;
  height: 72px;
  background: var(--primary-glow);
  border: 2px solid var(--primary);
  border-radius: var(--radius-full);
  display: flex;
  justify-content: center;
  align-items: center;
  margin: 0 auto 16px;
  font-size: 1.8rem;
  color: var(--primary);
}

.auth-hero h2 {
  font-size: 1.4rem;
  font-weight: 700;
  margin-bottom: 8px;
}

.auth-hero p {
  color: var(--text-muted);
  font-size: 0.88rem;
  line-height: 1.4;
}

.auth-tabs {
  display: flex;
  background: var(--bg-surface);
  border-radius: var(--radius-md);
  padding: 4px;
  margin-bottom: 22px;
}

.tab-btn {
  flex: 1;
  padding: 10px;
  background: transparent;
  border: none;
  color: var(--text-muted);
  font-weight: 600;
  font-size: 0.9rem;
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: all 0.2s ease;
}

.tab-btn.active {
  background: var(--primary);
  color: #fff;
  box-shadow: 0 4px 12px var(--primary-glow);
}

/* Forms */
.form-group {
  margin-bottom: 16px;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.form-group label {
  font-size: 0.82rem;
  font-weight: 600;
  color: var(--text-muted);
  display: flex;
  align-items: center;
  gap: 6px;
}

input, select {
  width: 100%;
  padding: 12px 14px;
  background: var(--bg-surface);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  color: var(--text-main);
  font-family: inherit;
  font-size: 0.95rem;
  outline: none;
  transition: all 0.2s ease;
}

input:focus, select:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px var(--primary-glow);
}

.role-selector {
  display: flex;
  gap: 10px;
}

.role-option {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 12px;
  background: var(--bg-surface);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  cursor: pointer;
  font-size: 0.88rem;
  font-weight: 600;
  transition: all 0.2s ease;
}

.role-option input {
  display: none;
}

.role-option.active {
  border-color: var(--primary);
  background: rgba(99, 102, 241, 0.15);
  color: var(--primary);
}

/* Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 12px 18px;
  border-radius: var(--radius-md);
  font-weight: 600;
  font-size: 0.92rem;
  border: none;
  cursor: pointer;
  transition: all 0.2s ease;
  font-family: inherit;
}

.btn-block {
  width: 100%;
}

.btn-primary {
  background: var(--primary);
  color: #fff;
  box-shadow: 0 4px 14px var(--primary-glow);
}

.btn-primary:hover {
  background: var(--primary-hover);
}

.btn-success {
  background: var(--success);
  color: #fff;
  box-shadow: 0 4px 14px var(--success-glow);
}

.btn-danger {
  background: var(--danger);
  color: #fff;
  box-shadow: 0 4px 14px var(--danger-glow);
}

.btn-outline {
  background: transparent;
  border: 1px solid var(--border-color);
  color: var(--text-main);
}

.btn-sm {
  padding: 8px 12px;
  font-size: 0.82rem;
  border-radius: var(--radius-sm);
}

/* Setup Screen */
.setup-card {
  padding: 30px 20px;
}

.setup-header {
  text-align: center;
  margin-bottom: 24px;
}

.setup-icon {
  width: 64px;
  height: 64px;
  background: rgba(16, 185, 129, 0.15);
  border-radius: 50%;
  display: flex;
  justify-content: center;
  align-items: center;
  font-size: 1.6rem;
  color: var(--success);
  margin: 0 auto 14px;
}

.setup-box {
  background: var(--bg-surface);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-lg);
  padding: 18px;
  margin-bottom: 14px;
}

.setup-box h3 {
  font-size: 1rem;
  margin-bottom: 6px;
  display: flex;
  align-items: center;
  gap: 8px;
}

.setup-box p {
  font-size: 0.82rem;
  color: var(--text-muted);
  margin-bottom: 14px;
}

.setup-divider {
  text-align: center;
  position: relative;
  margin: 20px 0;
}

.setup-divider::before {
  content: '';
  position: absolute;
  top: 50%;
  left: 0;
  right: 0;
  height: 1px;
  background: var(--border-color);
}

.setup-divider span {
  position: relative;
  background: var(--bg-main);
  padding: 0 12px;
  color: var(--text-dim);
  font-size: 0.78rem;
  font-weight: 700;
}

/* Map Screen */
#liveMap {
  width: 100%;
  height: 100%;
  z-index: 1;
}

.map-overlay-top {
  position: absolute;
  top: 14px;
  left: 14px;
  right: 14px;
  display: flex;
  justify-content: space-between;
  z-index: 500;
}

.family-pill {
  background: var(--bg-glass);
  backdrop-filter: blur(10px);
  border: 1px solid var(--border-color);
  padding: 8px 14px;
  border-radius: var(--radius-full);
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 0.85rem;
  font-weight: 700;
  box-shadow: var(--shadow-md);
  cursor: pointer;
}

.member-count-badge {
  background: var(--primary);
  color: #fff;
  font-size: 0.75rem;
  padding: 2px 7px;
  border-radius: var(--radius-full);
}

.gps-status-pill {
  background: var(--bg-glass);
  backdrop-filter: blur(10px);
  border: 1px solid var(--border-color);
  padding: 8px 12px;
  border-radius: var(--radius-full);
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 0.78rem;
  font-weight: 600;
  box-shadow: var(--shadow-md);
  cursor: pointer;
}

.pulse-dot {
  width: 8px;
  height: 8px;
  background: var(--success);
  border-radius: 50%;
  box-shadow: 0 0 0 3px var(--success-glow);
  animation: pulse-dot-anim 1.8s infinite;
}

@keyframes pulse-dot-anim {
  0% { transform: scale(0.9); box-shadow: 0 0 0 0 var(--success-glow); }
  70% { transform: scale(1.1); box-shadow: 0 0 0 6px rgba(16, 185, 129, 0); }
  100% { transform: scale(0.9); box-shadow: 0 0 0 0 rgba(16, 185, 129, 0); }
}

.map-overlay-bottom {
  position: absolute;
  bottom: 14px;
  left: 0;
  right: 0;
  z-index: 500;
  padding: 0 14px;
}

.members-carousel {
  display: flex;
  gap: 12px;
  overflow-x: auto;
  padding-bottom: 6px;
  scrollbar-width: none;
}

.members-carousel::-webkit-scrollbar {
  display: none;
}

.member-card {
  flex: 0 0 240px;
  background: var(--bg-glass);
  backdrop-filter: blur(12px);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-lg);
  padding: 14px;
  box-shadow: var(--shadow-lg);
  cursor: pointer;
  transition: transform 0.2s ease, border-color 0.2s ease;
}

.member-card:hover {
  transform: translateY(-2px);
  border-color: var(--primary);
}

.member-card-header {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 8px;
}

.member-avatar {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  background: var(--primary);
  display: flex;
  justify-content: center;
  align-items: center;
  font-weight: 700;
  font-size: 1rem;
  color: #fff;
  position: relative;
}

.member-name {
  font-weight: 700;
  font-size: 0.92rem;
}

.member-role {
  font-size: 0.74rem;
  color: var(--text-muted);
}

.member-status-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 0.78rem;
  color: var(--text-muted);
  border-top: 1px solid var(--border-color);
  padding-top: 8px;
  margin-top: 6px;
}

.battery-badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  font-weight: 600;
}

.battery-badge.low { color: var(--danger); }
.battery-badge.med { color: var(--warning); }
.battery-badge.high { color: var(--success); }

/* Floating Map Buttons */
.map-floating-actions {
  position: absolute;
  right: 14px;
  bottom: 120px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  z-index: 500;
}

.map-btn {
  width: 44px;
  height: 44px;
  border-radius: 50%;
  background: var(--bg-glass);
  backdrop-filter: blur(10px);
  border: 1px solid var(--border-color);
  color: var(--text-main);
  box-shadow: var(--shadow-md);
  display: flex;
  justify-content: center;
  align-items: center;
  font-size: 1.1rem;
  cursor: pointer;
  transition: all 0.2s ease;
}

.map-btn-sos {
  background: var(--danger);
  color: #fff;
  box-shadow: 0 4px 16px var(--danger-glow);
  animation: pulse-sos 2s infinite;
}

@keyframes pulse-sos {
  0% { transform: scale(1); }
  50% { transform: scale(1.08); box-shadow: 0 0 20px var(--danger); }
  100% { transform: scale(1); }
}

/* Bottom Navigation */
.bottom-nav {
  height: 64px;
  background: var(--bg-glass);
  backdrop-filter: blur(14px);
  border-top: 1px solid var(--border-color);
  display: flex;
  justify-content: space-around;
  align-items: center;
  z-index: 1000;
}

.nav-item {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  background: transparent;
  border: none;
  color: var(--text-dim);
  font-size: 0.72rem;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s ease;
}

.nav-item i {
  font-size: 1.25rem;
}

.nav-item.active {
  color: var(--primary);
}

/* Modals */
.modal-overlay {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(0, 0, 0, 0.75);
  backdrop-filter: blur(6px);
  z-index: 2000;
  display: flex;
  justify-content: center;
  align-items: flex-end;
  padding: 0;
}

.modal-content, .sos-modal-content {
  width: 100%;
  background: var(--bg-surface);
  border-top-left-radius: 28px;
  border-top-right-radius: 28px;
  border: 1px solid var(--border-color);
  padding: 24px 20px;
  box-shadow: var(--shadow-lg);
  max-height: 85vh;
  overflow-y: auto;
  animation: slide-up 0.3s cubic-bezier(0.16, 1, 0.3, 1);
}

@keyframes slide-up {
  from { transform: translateY(100%); }
  to { transform: translateY(0); }
}

.modal-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 18px;
}

.close-btn {
  background: transparent;
  border: none;
  font-size: 1.6rem;
  color: var(--text-muted);
  cursor: pointer;
}

/* SOS Modal */
.sos-modal-content {
  text-align: center;
  background: #180909;
  border-color: rgba(239, 68, 68, 0.3);
}

.sos-pulse-ring {
  width: 70px;
  height: 70px;
  background: rgba(239, 68, 68, 0.2);
  border: 2px solid var(--danger);
  border-radius: 50%;
  margin: 0 auto 12px;
  display: flex;
  justify-content: center;
  align-items: center;
  font-size: 2rem;
  color: var(--danger);
}

.btn-sos-big {
  width: 130px;
  height: 130px;
  border-radius: 50%;
  background: radial-gradient(circle, #ef4444 0%, #b91c1c 100%);
  border: 4px solid #fca5a5;
  color: #fff;
  font-weight: 800;
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  margin: 20px auto;
  cursor: pointer;
  box-shadow: 0 0 30px var(--danger-glow);
  transition: transform 0.15s ease;
}

.btn-sos-big:active {
  transform: scale(0.92);
}

.btn-sos-big span { font-size: 2rem; letter-spacing: 2px; }
.btn-sos-big small { font-size: 0.72rem; opacity: 0.85; }

/* Screens & Cards (Geofence, Timeline, Notifications, Profile) */
.screen-header {
  padding: 18px 18px 12px;
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.screen-header h2 { font-size: 1.25rem; font-weight: 700; }
.screen-header p { font-size: 0.82rem; color: var(--text-muted); }

.zones-list, .movements-list, .notifications-feed {
  padding: 0 18px 18px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.zone-card, .notif-card, .movement-card {
  background: var(--bg-surface);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  padding: 14px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.zone-icon-box {
  width: 44px;
  height: 44px;
  border-radius: var(--radius-md);
  background: rgba(99, 102, 241, 0.15);
  color: var(--primary);
  display: flex;
  justify-content: center;
  align-items: center;
  font-size: 1.2rem;
}

.zone-title { font-weight: 700; font-size: 0.95rem; }
.zone-subtitle { font-size: 0.78rem; color: var(--text-muted); }

.recent-movements-section {
  padding: 18px;
}

.recent-movements-section h3 {
  font-size: 0.95rem;
  margin-bottom: 12px;
  color: var(--text-muted);
}

/* Timeline */
.timeline-filter-card {
  padding: 0 18px 14px;
}

.form-row {
  display: flex;
  gap: 10px;
}

.flex-1 { flex: 1; }

.stats-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px;
  padding: 0 18px 14px;
}

.stat-card {
  background: var(--bg-surface);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  padding: 10px;
  display: flex;
  align-items: center;
  gap: 10px;
}

.stat-card i { font-size: 1.4rem; }
.stat-val { display: block; font-weight: 800; font-size: 0.95rem; }
.stat-lbl { display: block; font-size: 0.7rem; color: var(--text-dim); }

.timeline-map-box {
  height: 220px;
  margin: 0 18px 14px;
  border-radius: var(--radius-md);
  overflow: hidden;
  border: 1px solid var(--border-color);
}

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

/* Profile */
.profile-hero {
  text-align: center;
  padding: 24px 18px;
}

.profile-avatar-large {
  width: 72px;
  height: 72px;
  border-radius: 50%;
  background: var(--primary);
  color: #fff;
  font-size: 1.8rem;
  display: flex;
  justify-content: center;
  align-items: center;
  margin: 0 auto 12px;
}

.role-badge {
  display: inline-block;
  background: rgba(99, 102, 241, 0.2);
  color: var(--primary);
  padding: 3px 10px;
  border-radius: var(--radius-full);
  font-size: 0.75rem;
  font-weight: 700;
  margin: 4px 0;
}

.phone-display {
  display: block;
  font-size: 0.82rem;
  color: var(--text-muted);
}

.settings-group {
  padding: 0 18px 18px;
}

.settings-group h3 {
  font-size: 0.88rem;
  color: var(--text-dim);
  margin-bottom: 10px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.setting-item {
  background: var(--bg-surface);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  padding: 14px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 10px;
}

.setting-title { display: block; font-weight: 600; font-size: 0.9rem; }
.setting-desc { display: block; font-size: 0.76rem; color: var(--text-muted); }

/* Switch Toggle */
.toggle-switch {
  position: relative;
  display: inline-block;
  width: 46px;
  height: 26px;
}

.toggle-switch input { opacity: 0; width: 0; height: 0; }

.slider {
  position: absolute;
  cursor: pointer;
  top: 0; left: 0; right: 0; bottom: 0;
  background-color: var(--bg-surface-elevated);
  transition: .3s;
  border-radius: 34px;
}

.slider:before {
  position: absolute;
  content: "";
  height: 20px;
  width: 20px;
  left: 3px;
  bottom: 3px;
  background-color: white;
  transition: .3s;
  border-radius: 50%;
}

input:checked + .slider { background-color: var(--primary); }
input:checked + .slider:before { transform: translateX(20px); }

.invite-code-card {
  background: var(--bg-surface);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  padding: 14px;
}

.invite-code-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-top: 8px;
}

.code-box {
  font-size: 1.25rem;
  font-weight: 800;
  letter-spacing: 3px;
  color: var(--primary);
}

/* Toast Notification */
.toast-container {
  position: absolute;
  top: 70px;
  left: 20px;
  right: 20px;
  z-index: 3000;
  display: flex;
  flex-direction: column;
  gap: 8px;
  pointer-events: none;
}

.toast {
  background: var(--bg-surface-elevated);
  border: 1px solid var(--border-color);
  color: var(--text-main);
  padding: 12px 16px;
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-lg);
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 0.88rem;
  font-weight: 600;
  animation: toast-in 0.3s ease;
  pointer-events: auto;
}

.toast.toast-success { border-color: var(--success); }
.toast.toast-danger { border-color: var(--danger); background: #2a0e0e; }
.toast.toast-warning { border-color: var(--warning); }

@keyframes toast-in {
  from { transform: translateY(-20px); opacity: 0; }
  to { transform: translateY(0); opacity: 1; }
}

.mt-2 { margin-top: 8px; }
.mt-3 { margin-top: 14px; }
.text-primary { color: var(--primary); }
.text-success { color: var(--success); }
.text-danger { color: var(--danger); }
.text-warning { color: var(--warning); }
.text-info { color: #38bdf8; }
.text-purple { color: var(--purple); }
.text-muted { color: var(--text-muted); }
.small { font-size: 0.75rem; }
