:root {
  --navy: #0c1931;
  --muted: #657086;
  --blue: #0b63f6;
  --blue-dark: #004bd8;
  --green: #19b84b;
  --red: #e84444;
  --surface: rgba(255, 255, 255, 0.94);
  --line: #e7ebf2;
  --shadow: 0 18px 55px rgba(12, 25, 49, 0.16);
  font-family: Inter, ui-sans-serif, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  color: var(--navy);
}

* { box-sizing: border-box; }

[hidden] { display: none !important; }

html, body {
  width: 100%;
  height: 100%;
  margin: 0;
  overflow: hidden;
  background: #eaf0f7;
}

button { font: inherit; }

.app-shell {
  position: relative;
  width: 100%;
  height: 100dvh;
  overflow: hidden;
  isolation: isolate;
}

.map { position: absolute; inset: 0; z-index: 0; background: #e7edf3; }

.leaflet-control-attribution {
  margin-bottom: calc(292px + env(safe-area-inset-bottom)) !important;
  border-radius: 7px 0 0 0;
  font-size: 9px !important;
}

.topbar {
  position: absolute;
  z-index: 500;
  top: max(14px, env(safe-area-inset-top));
  left: 16px;
  right: 16px;
  height: 66px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 9px 10px 9px 18px;
  background: var(--surface);
  border: 1px solid rgba(255, 255, 255, 0.78);
  border-radius: 22px;
  box-shadow: 0 10px 35px rgba(22, 39, 68, 0.14);
  backdrop-filter: blur(18px);
}

.brand { display: flex; flex: 0 0 auto; align-items: center; gap: 9px; font-size: 22px; font-weight: 800; letter-spacing: -0.7px; }

.brand-mark {
  position: relative;
  width: 29px;
  height: 35px;
  display: grid;
  place-items: center;
  border-radius: 55% 55% 55% 10%;
  transform: rotate(-45deg);
  background: linear-gradient(145deg, #1784ff, #034fe2);
  box-shadow: 0 6px 15px rgba(11, 99, 246, 0.25);
}

.brand-mark span { width: 11px; height: 11px; border-radius: 50%; background: white; }

.avatar-button {
  flex: 0 0 auto;
  width: 46px;
  height: 46px;
  border: 3px solid white;
  border-radius: 50%;
  color: white;
  background: linear-gradient(145deg, #263b5d, #101d34);
  box-shadow: 0 3px 12px rgba(12, 25, 49, 0.2);
  font-weight: 800;
  cursor: pointer;
}

.group-switcher {
  min-width: 0;
  max-width: 145px;
  height: 38px;
  display: flex;
  align-items: center;
  gap: 5px;
  margin-left: auto;
  padding: 0 8px 0 11px;
  border: 1px solid #e0e6ef;
  border-radius: 12px;
  color: #33405a;
  background: #f7f9fc;
  font-size: 12px;
  font-weight: 750;
  cursor: pointer;
}

.group-switcher span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.group-switcher svg { flex: 0 0 auto; width: 17px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }

.live-badge {
  position: absolute;
  z-index: 500;
  top: calc(max(14px, env(safe-area-inset-top)) + 80px);
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  align-items: center;
  gap: 9px;
  white-space: nowrap;
  padding: 11px 16px;
  border-radius: 15px;
  background: rgba(255, 255, 255, 0.94);
  box-shadow: 0 8px 25px rgba(12, 25, 49, 0.13);
  color: #273248;
  font-size: 13px;
  font-weight: 750;
  backdrop-filter: blur(16px);
}

.status-dot { width: 9px; height: 9px; border-radius: 50%; background: #a7afbc; }
.live-badge.is-live .status-dot { background: var(--green); box-shadow: 0 0 0 5px rgba(25, 184, 75, 0.13); animation: pulse-dot 1.7s infinite; }

.map-action {
  position: absolute;
  z-index: 500;
  right: 18px;
  bottom: calc(302px + env(safe-area-inset-bottom));
  width: 54px;
  height: 54px;
  display: grid;
  place-items: center;
  border: 0;
  border-radius: 18px;
  background: rgba(255, 255, 255, 0.96);
  color: var(--blue);
  box-shadow: 0 10px 28px rgba(12, 25, 49, 0.17);
  cursor: pointer;
}

.map-action svg { width: 29px; fill: none; stroke: currentColor; stroke-width: 2.2; }

.bottom-sheet {
  position: absolute;
  z-index: 600;
  left: 0;
  right: 0;
  bottom: 0;
  min-height: 280px;
  padding: 10px 18px calc(14px + env(safe-area-inset-bottom));
  border-radius: 30px 30px 0 0;
  background: rgba(255, 255, 255, 0.97);
  box-shadow: 0 -14px 45px rgba(12, 25, 49, 0.13);
  backdrop-filter: blur(20px);
}

.sheet-handle { width: 42px; height: 5px; margin: 0 auto 12px; border-radius: 99px; background: #d6dae2; }
.sheet-heading { display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; margin-bottom: 12px; }
.sheet-heading h1 { margin: 0 0 2px; font-size: 27px; line-height: 1.05; letter-spacing: -1px; }
.sheet-heading p { margin: 0; color: var(--muted); font-size: 13px; }

.invite-button {
  min-height: 40px;
  display: flex;
  align-items: center;
  gap: 7px;
  padding: 0 12px;
  border: 1px solid #dce4f0;
  border-radius: 13px;
  color: var(--blue);
  background: #f7faff;
  font-size: 12px;
  font-weight: 750;
  cursor: pointer;
}

.invite-button svg { width: 17px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }

.friends-list { display: flex; gap: 8px; min-height: 86px; margin: 0 -4px 13px; padding: 0 4px 3px; overflow-x: auto; scrollbar-width: none; }
.friends-list::-webkit-scrollbar { display: none; }

.friend-card {
  flex: 0 0 104px;
  min-width: 104px;
  padding: 10px 8px;
  border: 1px solid var(--line);
  border-radius: 17px;
  background: #fff;
  text-align: left;
  box-shadow: 0 4px 14px rgba(22, 39, 68, 0.06);
  cursor: pointer;
  transition: transform 160ms ease, border-color 160ms ease, box-shadow 160ms ease;
}

.friend-card:active { transform: scale(0.97); }
.friend-card.is-selected { border-color: rgba(11, 99, 246, 0.5); box-shadow: 0 5px 18px rgba(11, 99, 246, 0.13); }
.friend-card.is-offline { opacity: 0.62; }
.friend-avatar { width: 35px; height: 35px; display: grid; place-items: center; margin-bottom: 6px; border-radius: 50%; color: white; font-size: 12px; font-weight: 800; }
.friend-avatar img { width: 100%; height: 100%; border-radius: inherit; object-fit: cover; }
.friend-name { display: block; overflow: hidden; color: var(--navy); font-size: 13px; font-weight: 800; text-overflow: ellipsis; white-space: nowrap; }
.friend-distance { display: block; overflow: hidden; margin-top: 2px; color: var(--muted); font-size: 10px; text-overflow: ellipsis; white-space: nowrap; }

.tracking-actions { display: flex; gap: 9px; }
.primary-button, .stop-button {
  min-height: 52px;
  border: 0;
  border-radius: 17px;
  font-weight: 800;
  cursor: pointer;
}

.primary-button {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 9px;
  padding: 0 14px;
  color: white;
  background: linear-gradient(135deg, #1273ff, #0754e8);
  box-shadow: 0 9px 22px rgba(11, 99, 246, 0.25);
  font-size: 14px;
}

.primary-button svg, .stop-button svg { width: 22px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.primary-button.is-live { background: linear-gradient(135deg, #0d64ee, #004acb); }
.stop-button { width: 54px; display: grid; place-items: center; color: var(--red); background: #fff3f3; border: 1px solid #ffd5d5; }
.stop-button[hidden] { display: none; }
.privacy-note { margin: 8px 2px 0; color: #8a93a3; font-size: 10px; text-align: center; }

.toast {
  position: absolute;
  z-index: 900;
  left: 50%;
  bottom: calc(300px + env(safe-area-inset-bottom));
  max-width: calc(100% - 40px);
  padding: 11px 15px;
  border-radius: 13px;
  background: #0c1931;
  color: white;
  font-size: 12px;
  font-weight: 650;
  opacity: 0;
  pointer-events: none;
  transform: translate(-50%, 10px);
  transition: 180ms ease;
}

.toast.is-visible { opacity: 1; transform: translate(-50%, 0); }

.user-location-marker { background: transparent; border: 0; }
.user-marker-core {
  position: absolute;
  left: 50%;
  top: 50%;
  width: 24px;
  height: 24px;
  border: 5px solid white;
  border-radius: 50%;
  background: var(--blue);
  box-shadow: 0 4px 14px rgba(0, 75, 216, 0.4);
  transform: translate(-50%, -50%);
}
.user-marker-pulse { position: absolute; inset: 0; border-radius: 50%; background: rgba(11, 99, 246, 0.2); animation: location-pulse 2s ease-out infinite; }
.friend-map-marker { position: relative; width: 44px; height: 51px; }
.friend-pin { position: absolute; inset: 0 0 7px; display: grid; place-items: center; border: 4px solid white; border-radius: 50% 50% 50% 12px; color: white; font-size: 12px; font-weight: 850; transform: rotate(-45deg); box-shadow: 0 5px 15px rgba(12, 25, 49, 0.24); }
.friend-pin span { transform: rotate(45deg); }
.friend-pin img { width: 100%; height: 100%; border-radius: inherit; object-fit: cover; transform: rotate(45deg); }
.friend-map-marker.is-selected .friend-pin { outline: 4px solid rgba(11, 99, 246, 0.2); transform: rotate(-45deg) scale(1.12); }
.friend-map-marker.is-stale { opacity: 0.58; filter: grayscale(0.3); }

.friends-empty {
  width: 100%;
  display: grid;
  place-items: center;
  border: 1px dashed #dce3ed;
  border-radius: 16px;
  color: var(--muted);
  background: #fafbfd;
  font-size: 12px;
  text-align: center;
}

.auth-screen {
  position: absolute;
  z-index: 1000;
  inset: 0;
  display: flex;
  flex-direction: column;
  padding: calc(28px + env(safe-area-inset-top)) 20px calc(20px + env(safe-area-inset-bottom));
  background:
    radial-gradient(circle at 80% 8%, rgba(24, 124, 255, 0.22), transparent 34%),
    linear-gradient(165deg, #f8fbff 0%, #eaf2ff 48%, #ffffff 100%);
  overflow-y: auto;
}

.auth-brand { display: flex; align-items: center; gap: 10px; color: var(--navy); font-size: 24px; font-weight: 850; letter-spacing: -0.8px; }
.auth-copy { margin: auto 4px 28px; }
.auth-copy h1 { max-width: 310px; margin: 0 0 12px; color: var(--navy); font-size: clamp(38px, 11vw, 52px); line-height: 0.98; letter-spacing: -2.4px; }
.auth-copy p { max-width: 330px; margin: 0; color: #55637a; font-size: 16px; line-height: 1.5; }

.auth-panel {
  padding: 8px 16px 18px;
  border: 1px solid rgba(255, 255, 255, 0.9);
  border-radius: 25px;
  background: rgba(255, 255, 255, 0.9);
  box-shadow: 0 18px 50px rgba(12, 44, 95, 0.13);
  backdrop-filter: blur(18px);
}

.auth-tabs { display: grid; grid-template-columns: 1fr 1fr; gap: 4px; margin-bottom: 14px; padding: 4px; border-radius: 14px; background: #edf2f8; }
.auth-tab { min-height: 40px; border: 0; border-radius: 11px; color: #68758a; background: transparent; font-size: 13px; font-weight: 800; cursor: pointer; }
.auth-tab.is-active { color: var(--navy); background: white; box-shadow: 0 3px 12px rgba(25, 48, 85, 0.08); }

.field { display: block; margin-bottom: 12px; }
.field > span { display: block; margin: 0 2px 6px; color: #46536a; font-size: 11px; font-weight: 800; }
.field input {
  width: 100%;
  min-height: 48px;
  padding: 0 14px;
  border: 1px solid #dfe5ee;
  border-radius: 14px;
  outline: none;
  color: var(--navy);
  background: white;
  font: 650 14px/1.2 inherit;
  transition: border-color 160ms ease, box-shadow 160ms ease;
}
.field input:focus { border-color: #65a1ff; box-shadow: 0 0 0 4px rgba(11, 99, 246, 0.1); }
.field input::placeholder { color: #9ba5b5; font-weight: 500; }
.field small { color: #8a95a7; font-weight: 600; }
.auth-panel .primary-button, .modal-form .primary-button, .empty-state .primary-button { width: 100%; }
.form-message { min-height: 16px; margin: 8px 2px 0; color: #cf3333; font-size: 11px; text-align: center; }

.empty-state {
  position: absolute;
  z-index: 550;
  top: 50%;
  left: 20px;
  right: 20px;
  transform: translateY(-46%);
  padding: 28px 22px;
  border: 1px solid rgba(255, 255, 255, 0.9);
  border-radius: 26px;
  background: rgba(255, 255, 255, 0.94);
  box-shadow: var(--shadow);
  text-align: center;
  backdrop-filter: blur(18px);
}
.empty-icon { width: 64px; height: 64px; display: grid; place-items: center; margin: 0 auto 16px; border-radius: 20px; color: var(--blue); background: #eaf2ff; }
.empty-icon svg { width: 31px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.empty-state h1 { margin: 0 0 8px; font-size: 25px; letter-spacing: -0.9px; }
.empty-state p { margin: 0 0 20px; color: var(--muted); font-size: 13px; line-height: 1.5; }
.text-button, .danger-text-button { border: 0; background: transparent; font-weight: 800; cursor: pointer; }
.text-button { margin-top: 13px; color: var(--blue); font-size: 13px; }
.danger-text-button { width: 100%; margin-top: 16px; padding: 10px; color: #d83d3d; font-size: 12px; }

.modal-backdrop {
  position: absolute;
  z-index: 1200;
  inset: 0;
  display: flex;
  align-items: flex-end;
  padding-top: env(safe-area-inset-top);
  background: rgba(8, 18, 36, 0.4);
  opacity: 0;
  transition: opacity 160ms ease;
  backdrop-filter: blur(4px);
}
.modal-backdrop.is-open { opacity: 1; }
.modal {
  width: 100%;
  max-height: 86%;
  padding: 11px 19px calc(20px + env(safe-area-inset-bottom));
  border-radius: 28px 28px 0 0;
  background: white;
  box-shadow: 0 -18px 55px rgba(6, 20, 45, 0.22);
  overflow-y: auto;
  transform: translateY(24px);
  transition: transform 180ms ease;
}
.modal-backdrop.is-open .modal { transform: translateY(0); }
.modal::before { content: ''; display: block; width: 42px; height: 5px; margin: 0 auto 17px; border-radius: 99px; background: #d8dde5; }
.modal-header { display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; margin-bottom: 18px; }
.modal-header h2 { margin: 0 0 3px; font-size: 25px; letter-spacing: -0.9px; }
.modal-header p { margin: 0; color: var(--muted); font-size: 12px; }
.icon-button { width: 40px; height: 40px; display: grid; flex: 0 0 auto; place-items: center; border: 0; border-radius: 13px; color: #59667b; background: #f1f4f8; cursor: pointer; }
.icon-button svg { width: 20px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; }
.modal-form .primary-button { margin-top: 4px; }
.modal-actions { display: grid; gap: 9px; margin-top: 16px; }
.modal-actions.two-columns { grid-template-columns: 1fr 1fr; }
.secondary-button { min-height: 52px; padding: 0 12px; border: 1px solid #dce4ef; border-radius: 17px; color: var(--blue); background: #f7faff; font-size: 12px; font-weight: 800; cursor: pointer; }
.group-list { display: grid; gap: 8px; }
.group-row { width: 100%; display: grid; grid-template-columns: 44px 1fr 20px; align-items: center; gap: 11px; padding: 10px; border: 1px solid #e4e8ef; border-radius: 16px; color: var(--navy); background: white; text-align: left; cursor: pointer; }
.group-row.is-active { border-color: #78aaf9; background: #f5f9ff; }
.group-row-icon { width: 44px; height: 44px; display: grid; place-items: center; border-radius: 14px; color: white; background: linear-gradient(145deg, #1784ff, #034fe2); font-size: 12px; font-weight: 850; }
.group-row strong, .group-row small { display: block; }
.group-row strong { overflow: hidden; font-size: 14px; text-overflow: ellipsis; white-space: nowrap; }
.group-row small { margin-top: 2px; color: var(--muted); font-size: 10px; }
.group-row svg { width: 19px; fill: none; stroke: #8b96a7; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.modal-empty { padding: 15px; color: var(--muted); font-size: 13px; text-align: center; }
.color-input { height: 48px; padding: 5px !important; cursor: pointer; }

@keyframes location-pulse { 0% { transform: scale(0.45); opacity: 1; } 100% { transform: scale(1.45); opacity: 0; } }
@keyframes pulse-dot { 50% { opacity: 0.55; } }

@media (min-width: 700px) {
  body { display: grid; place-items: center; padding: 24px; }
  .app-shell { width: 390px; height: min(844px, calc(100dvh - 48px)); border-radius: 34px; box-shadow: 0 30px 80px rgba(12, 25, 49, 0.28); }
  .bottom-sheet { border-radius: 30px 30px 34px 34px; }
}

@media (max-height: 690px) {
  .bottom-sheet { padding-top: 7px; }
  .sheet-handle { margin-bottom: 8px; }
  .sheet-heading { margin-bottom: 8px; }
  .sheet-heading h1 { font-size: 23px; }
  .friend-card { padding: 7px; }
  .friend-avatar { width: 29px; height: 29px; margin-bottom: 4px; }
  .privacy-note { display: none; }
  .map-action, .toast { bottom: calc(270px + env(safe-area-inset-bottom)); }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: 0.01ms !important; animation-iteration-count: 1 !important; scroll-behavior: auto !important; }
}
