:root {
  --bg: #0B0F1A;
  --surface: #131929;
  --card: #1A2235;
  --border: #1F2D45;
  --accent: #3B82F6;
  --green: #10B981;
  --red: #EF4444;
  --yellow: #F59E0B;
  --text: #E2E8F0;
  --muted: #64748B;
}

* { box-sizing: border-box; margin: 0; padding: 0; }

body {
  font-family: -apple-system, 'Inter', system-ui, sans-serif;
  background: var(--bg);
  color: var(--text);
  overflow: hidden;
}

.screen { display: none; height: 100vh; }
.screen.active { display: flex; }

/* ── Auth Screen ─────────────────────────────────────────── */
#screen-auth {
  align-items: center;
  justify-content: center;
  background: radial-gradient(circle at 30% 20%, #1d2a4a 0%, var(--bg) 60%);
}

.auth-card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 20px;
  padding: 36px 32px;
  width: 100%;
  max-width: 380px;
  backdrop-filter: blur(20px);
}

.logo { font-size: 24px; font-weight: 700; text-align: center; margin-bottom: 4px; }
.subtitle { text-align: center; color: var(--muted); font-size: 13px; margin-bottom: 24px; }

.tabs { display: flex; gap: 4px; background: var(--surface); border-radius: 10px; padding: 4px; margin-bottom: 20px; }
.tab { flex: 1; padding: 10px; background: none; border: none; color: var(--muted); border-radius: 8px; cursor: pointer; font-size: 13px; font-weight: 600; }
.tab.active { background: var(--accent); color: white; }

.auth-form { display: none; flex-direction: column; gap: 12px; }
.auth-form.active { display: flex; }

input, textarea {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 12px 14px;
  color: var(--text);
  font-size: 14px;
  width: 100%;
  font-family: inherit;
}
input:focus, textarea:focus { outline: none; border-color: var(--accent); }
textarea { resize: vertical; min-height: 60px; }

.btn-primary {
  background: linear-gradient(135deg, var(--accent), #1D4ED8);
  border: none;
  color: white;
  padding: 13px;
  border-radius: 10px;
  font-weight: 600;
  cursor: pointer;
  font-size: 14px;
  margin-top: 4px;
}
.btn-primary:active { transform: scale(0.98); }

.btn-secondary {
  background: var(--surface);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 13px;
  border-radius: 10px;
  cursor: pointer;
  font-size: 14px;
}

.btn-danger {
  background: var(--red);
  border: none;
  color: white;
  padding: 13px;
  border-radius: 10px;
  font-weight: 700;
  cursor: pointer;
  font-size: 14px;
}

.btn-link { background: none; border: none; color: var(--accent); font-size: 12px; cursor: pointer; text-align: center; }

.error { color: var(--red); font-size: 12px; min-height: 16px; }
.otp-info { font-size: 13px; color: var(--muted); text-align: center; margin-bottom: 8px; }
#otp-code { text-align: center; font-size: 22px; letter-spacing: 8px; }

/* ── Main Screen ──────────────────────────────────────────── */
#screen-main { flex-direction: column; width: 100%; }

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 16px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  z-index: 1000;
}

.logo-small { font-size: 16px; font-weight: 700; }
.topbar-actions { display: flex; gap: 8px; align-items: center; }

.icon-btn {
  background: var(--card);
  border: 1px solid var(--border);
  width: 38px;
  height: 38px;
  border-radius: 10px;
  cursor: pointer;
  font-size: 16px;
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
}

.sos-btn {
  background: var(--red);
  border: none;
  color: white;
  padding: 0 16px;
  height: 38px;
  border-radius: 10px;
  font-weight: 700;
  font-size: 13px;
  cursor: pointer;
  box-shadow: 0 0 0 0 rgba(239,68,68,0.6);
  animation: pulse 2s infinite;
}

@keyframes pulse {
  0%   { box-shadow: 0 0 0 0 rgba(239,68,68,0.5); }
  70%  { box-shadow: 0 0 0 10px rgba(239,68,68,0); }
  100% { box-shadow: 0 0 0 0 rgba(239,68,68,0); }
}

.badge {
  position: absolute;
  top: -4px;
  right: -4px;
  background: var(--red);
  color: white;
  font-size: 10px;
  font-weight: 700;
  width: 16px;
  height: 16px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
}
.badge.hidden { display: none; }

#map { flex: 1; width: 100%; z-index: 1; }

.status-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 16px;
  background: var(--surface);
  border-top: 1px solid var(--border);
  font-size: 13px;
  color: var(--muted);
}

.toggle { position: relative; width: 44px; height: 24px; }
.toggle input { opacity: 0; width: 0; height: 0; }
.toggle-slider {
  position: absolute; inset: 0; background: var(--border);
  border-radius: 24px; cursor: pointer; transition: 0.2s;
}
.toggle-slider::before {
  content: ''; position: absolute; height: 18px; width: 18px;
  left: 3px; bottom: 3px; background: white; border-radius: 50%; transition: 0.2s;
}
.toggle input:checked + .toggle-slider { background: var(--green); }
.toggle input:checked + .toggle-slider::before { transform: translateX(20px); }

/* ── Modals ───────────────────────────────────────────────── */
.modal {
  display: none;
  position: fixed; inset: 0;
  background: rgba(0,0,0,0.6);
  z-index: 2000;
  align-items: flex-end;
  justify-content: center;
}
.modal.active { display: flex; }

.modal-content {
  background: var(--card);
  border-radius: 20px 20px 0 0;
  padding: 24px;
  width: 100%;
  max-width: 480px;
  max-height: 80vh;
  overflow-y: auto;
}

.sos-modal { border-radius: 20px; text-align: center; margin: auto; }
.sos-modal h3 { margin-bottom: 12px; color: var(--red); }
.sos-modal p { color: var(--muted); font-size: 14px; margin-bottom: 20px; }
.sos-actions { display: flex; flex-direction: column; gap: 10px; }

.modal-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 16px; }
.modal-header h3 { font-size: 16px; }
.modal-close { background: none; border: none; color: var(--muted); font-size: 18px; cursor: pointer; }

.modal-tabs { display: flex; gap: 8px; margin-bottom: 16px; }
.mtab { background: var(--surface); border: 1px solid var(--border); color: var(--muted); padding: 8px 16px; border-radius: 8px; font-size: 12px; cursor: pointer; }
.mtab.active { background: var(--accent); color: white; border-color: var(--accent); }

.list-container { display: flex; flex-direction: column; gap: 10px; min-height: 40px; }
.list-item {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 14px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
}
.list-item-info { flex: 1; }
.list-item-name { font-size: 13px; font-weight: 600; }
.list-item-meta { font-size: 11px; color: var(--muted); margin-top: 2px; }
.list-item-actions { display: flex; gap: 6px; }
.btn-sm { padding: 6px 12px; border-radius: 8px; border: none; font-size: 11px; font-weight: 600; cursor: pointer; }
.btn-accept { background: var(--green); color: white; }
.btn-decline { background: var(--border); color: var(--text); }
.btn-revoke { background: var(--red); color: white; }

.divider { height: 1px; background: var(--border); margin: 20px 0; }
.hint { font-size: 12px; color: var(--muted); margin-bottom: 10px; }
.empty-state { text-align: center; color: var(--muted); font-size: 13px; padding: 20px; }

/* ── Toast ────────────────────────────────────────────────── */
#toast-container { position: fixed; top: 16px; left: 50%; transform: translateX(-50%); z-index: 3000; display: flex; flex-direction: column; gap: 8px; }
.toast {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 12px 20px;
  font-size: 13px;
  box-shadow: 0 4px 20px rgba(0,0,0,0.3);
  animation: slideDown 0.3s ease;
}
.toast.success { border-color: var(--green); }
.toast.error { border-color: var(--red); }
@keyframes slideDown { from { opacity: 0; transform: translateY(-10px); } to { opacity: 1; transform: translateY(0); } }

/* Leaflet popup dark theme override */
.leaflet-popup-content-wrapper, .leaflet-popup-tip { background: var(--card); color: var(--text); }
