:root {
  color-scheme: light;
  --ink: #17211f;
  --muted: #66736f;
  --line: #dde5e2;
  --surface: #f7f9f8;
  --panel: rgba(255, 255, 255, 0.96);
  --accent: #e85d3f;
  --accent-2: #1f8a70;
  --shadow: 0 12px 30px rgba(30, 43, 39, 0.16);
  --radius: 8px;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC",
    "Hiragino Sans GB", "Microsoft YaHei", sans-serif;
  -webkit-font-smoothing: antialiased;
}

* {
  box-sizing: border-box;
}

html,
body {
  height: 100%;
  margin: 0;
}

body {
  background: var(--surface);
  color: var(--ink);
  overscroll-behavior: none;
}

button,
input,
textarea,
select {
  font: inherit;
}

button {
  color: inherit;
}

.map-app {
  position: relative;
  width: 100%;
  height: 100%;
  overflow: hidden;
  background: #e8eeeb;
}

.map-canvas {
  position: absolute;
  inset: 0;
  z-index: 1;
  background: #dfe7e3;
}

.leaflet-container {
  background: #dde7e3;
  font-family: inherit;
}

.leaflet-control-zoom a {
  color: var(--ink);
}

.topbar {
  position: absolute;
  top: max(10px, env(safe-area-inset-top));
  left: 12px;
  right: 12px;
  z-index: 700;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 8px 10px 8px 12px;
  background: var(--panel);
  border: 1px solid rgba(255, 255, 255, 0.8);
  border-radius: var(--radius);
  box-shadow: 0 6px 18px rgba(34, 47, 43, 0.13);
  backdrop-filter: blur(14px);
  pointer-events: auto;
}

.brand-lockup {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
}

.brand-badge {
  position: relative;
  width: 34px;
  height: 34px;
  flex: 0 0 auto;
  border-radius: 50%;
  background: linear-gradient(145deg, var(--accent), #f69b43);
  box-shadow: inset 0 0 0 2px rgba(255, 255, 255, 0.6);
}

.brand-badge::after {
  content: "";
  position: absolute;
  left: 50%;
  top: 17px;
  width: 11px;
  height: 11px;
  border-radius: 50% 50% 50% 0;
  background: #fff;
  transform: translate(-50%, -50%) rotate(-45deg);
}

.brand-copy {
  display: grid;
  gap: 1px;
  min-width: 0;
}

.brand-copy strong {
  font-size: 16px;
  line-height: 1.2;
  font-weight: 750;
  letter-spacing: 0;
  white-space: nowrap;
}

.brand-copy span {
  color: var(--muted);
  font-size: 12px;
  line-height: 1.2;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.top-actions {
  display: flex;
  align-items: center;
  gap: 8px;
}

.icon-button {
  display: inline-grid;
  place-items: center;
  width: 38px;
  height: 38px;
  padding: 0;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: #fff;
  cursor: pointer;
  color: var(--ink);
  box-shadow: 0 2px 8px rgba(34, 47, 43, 0.08);
  transition: background 0.15s ease, transform 0.15s ease;
}

.icon-button:hover {
  background: #f2f6f4;
}

.icon-button:active {
  transform: scale(0.96);
}

.icon-button svg {
  width: 19px;
  height: 19px;
}

.people-panel {
  position: absolute;
  z-index: 800;
  left: 10px;
  right: 10px;
  bottom: max(10px, env(safe-area-inset-bottom));
  display: flex;
  flex-direction: column;
  height: min(48dvh, 430px);
  min-height: 270px;
  padding: 8px 12px 12px;
  overflow: hidden;
  background: var(--panel);
  border: 1px solid rgba(255, 255, 255, 0.85);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  backdrop-filter: blur(18px);
  transition: height 0.22s ease;
}

.people-panel.is-compact {
  height: 146px;
  min-height: 146px;
}

.people-panel.is-compact .people-list,
.people-panel.is-compact .tag-filters,
.people-panel.is-compact .empty-state {
  opacity: 0;
  pointer-events: none;
}

.panel-handle {
  display: flex;
  align-items: center;
  justify-content: center;
  height: 18px;
  margin: -4px auto 2px;
  width: 56px;
  cursor: pointer;
  border-radius: 12px;
}

.handle-line {
  width: 36px;
  height: 4px;
  border-radius: 4px;
  background: #c9d4d0;
}

.panel-heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  min-height: 42px;
}

.panel-heading h1 {
  margin: 0;
  font-size: 17px;
  line-height: 1.25;
  font-weight: 750;
  letter-spacing: 0;
}

.panel-heading p {
  margin: 2px 0 0;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.2;
}

.count-badge {
  min-width: 30px;
  height: 26px;
  padding: 0 9px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: 13px;
  background: #e7f3ef;
  color: #156f5b;
  font-size: 13px;
  font-weight: 700;
}

.tag-filters {
  display: flex;
  gap: 8px;
  overflow-x: auto;
  padding: 6px 2px 7px;
  scrollbar-width: none;
}

.tag-filters::-webkit-scrollbar {
  display: none;
}

.tag-chip {
  flex: 0 0 auto;
  display: inline-flex;
  align-items: center;
  gap: 5px;
  height: 30px;
  padding: 0 11px;
  border: 1px solid var(--line);
  border-radius: 15px;
  background: #fff;
  color: #51605b;
  font-size: 13px;
  cursor: pointer;
}

.tag-chip .tag-count {
  color: #8b9994;
  font-size: 11px;
}

.tag-chip.is-active {
  border-color: #1f8a70;
  background: #1f8a70;
  color: #fff;
}

.tag-chip.is-active .tag-count {
  color: rgba(255, 255, 255, 0.72);
}

.people-list {
  display: grid;
  gap: 8px;
  min-height: 0;
  overflow-y: auto;
  padding: 0 1px 8px;
  scrollbar-width: thin;
}

.person-row {
  width: 100%;
  display: grid;
  grid-template-columns: 48px minmax(0, 1fr) auto;
  align-items: center;
  gap: 12px;
  padding: 10px;
  border: 1px solid transparent;
  border-radius: var(--radius);
  background: #f4f7f5;
  text-align: left;
  cursor: pointer;
  transition: border-color 0.15s ease, background 0.15s ease;
}

.person-row:hover {
  background: #edf4f0;
  border-color: #cde2da;
}

.person-row.is-focused {
  border-color: rgba(232, 93, 63, 0.72);
  background: #fff5f1;
}

.avatar-holder {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex: 0 0 auto;
  width: 44px;
  height: 44px;
  overflow: hidden;
  border-radius: 50%;
  background: #e4ece8;
  color: #fff;
  font-weight: 750;
  user-select: none;
}

.avatar-holder img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.avatar-holder.is-sm {
  width: 38px;
  height: 38px;
  font-size: 15px;
}

.avatar-holder.is-md {
  width: 48px;
  height: 48px;
  font-size: 18px;
}

.avatar-holder.is-lg {
  width: 88px;
  height: 88px;
  font-size: 30px;
  box-shadow: 0 8px 22px rgba(35, 48, 44, 0.2);
}

.avatar-fallback {
  background: linear-gradient(145deg, var(--avatar-a), var(--avatar-b));
}

.person-copy {
  min-width: 0;
}

.person-name-line {
  display: flex;
  align-items: center;
  gap: 7px;
  min-width: 0;
}

.person-name-line strong {
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
  font-size: 15px;
  font-weight: 700;
}

.presence-text {
  flex: 0 0 auto;
  display: inline-flex;
  align-items: center;
  gap: 4px;
  color: #1f8a70;
  font-size: 11px;
  font-weight: 650;
}

.presence-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: #20a97d;
}

.person-meta {
  display: block;
  margin-top: 2px;
  color: var(--muted);
  font-size: 12px;
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
}

.person-tags {
  display: flex;
  gap: 5px;
  margin-top: 5px;
  overflow: hidden;
  white-space: nowrap;
}

.person-tag {
  display: inline-block;
  padding: 2px 7px;
  border-radius: 10px;
  background: #e6efec;
  color: #48645b;
  font-size: 11px;
  font-weight: 600;
}

.row-distance {
  min-width: 52px;
  color: #77847f;
  text-align: right;
  font-size: 12px;
  font-weight: 650;
}

.empty-state {
  display: grid;
  place-items: center;
  gap: 8px;
  padding: 24px 0;
  color: var(--muted);
  text-align: center;
}

.empty-state p {
  margin: 0;
}

.empty-mark {
  display: grid;
  place-items: center;
  width: 46px;
  height: 46px;
  border: 1px solid var(--line);
  border-radius: 50%;
  background: #eef4f1;
  color: #7b8983;
  font-weight: 700;
}

.avatar-marker-button {
  display: grid;
  place-items: center;
  width: 48px;
  height: 48px;
  margin: 0;
  padding: 0;
  border: 3px solid #fff;
  border-radius: 50%;
  background: #fff;
  cursor: pointer;
  box-shadow: 0 3px 10px rgba(29, 44, 39, 0.24);
  overflow: visible;
  transition: transform 0.14s ease, border-color 0.14s ease;
}

.avatar-marker-button:hover {
  transform: translateY(-2px) scale(1.06);
}

.avatar-marker-button .avatar-holder {
  width: 38px;
  height: 38px;
  border-radius: 50%;
  font-size: 15px;
}

.avatar-marker-button .avatar-holder img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  border-radius: 50%;
}

.avatar-marker-button .presence-dot {
  position: absolute;
  right: -1px;
  bottom: 0;
  width: 13px;
  height: 13px;
  border: 3px solid #fff;
  border-radius: 50%;
  background: #20a97d;
}

.avatar-marker-button.is-offline .presence-dot {
  background: #a8b4ae;
}

.avatar-marker-button.is-active {
  border-color: var(--accent);
  transform: translateY(-4px) scale(1.08);
  box-shadow: 0 6px 16px rgba(232, 93, 63, 0.34);
}

.profile-sheet {
  position: absolute;
  z-index: 1200;
  inset: 0;
  display: flex;
  flex-direction: column;
  padding: max(12px, env(safe-area-inset-top)) 12px max(12px, env(safe-area-inset-bottom));
  background: #fff;
  transform: translateY(104%);
  opacity: 0;
  visibility: hidden;
  transition: transform 0.24s ease, opacity 0.24s ease, visibility 0.24s;
}

.profile-sheet.is-open {
  transform: translateY(0);
  opacity: 1;
  visibility: visible;
}

.sheet-topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 10px;
}

.sheet-pager {
  color: var(--muted);
  font-size: 13px;
  font-weight: 650;
}

.profile-body {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  padding: 4px 2px 18px;
  scrollbar-width: thin;
}

.profile-hero {
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 12px 8px 18px;
  border-bottom: 1px solid var(--line);
}

.profile-copy {
  min-width: 0;
}

.profile-copy h2 {
  margin: 0 0 5px;
  font-size: 24px;
  line-height: 1.2;
  font-weight: 800;
  letter-spacing: 0;
}

.profile-area {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  margin-bottom: 10px;
  color: #1f8a70;
  font-size: 13px;
  font-weight: 650;
}

.profile-area svg {
  width: 14px;
  height: 14px;
}

.profile-distance {
  color: var(--muted);
  font-size: 13px;
}

.profile-section {
  padding: 16px 8px;
  border-bottom: 1px solid var(--line);
}

.profile-section:last-child {
  border-bottom: 0;
}

.section-label {
  display: block;
  margin-bottom: 8px;
  color: #8a9792;
  font-size: 12px;
  font-weight: 700;
}

.profile-bio {
  margin: 0;
  color: #27332f;
  font-size: 15px;
  line-height: 1.7;
}

.profile-tag-list {
  display: flex;
  flex-wrap: wrap;
  gap: 7px;
}

.profile-tag-list span {
  display: inline-flex;
  align-items: center;
  min-height: 26px;
  padding: 0 10px;
  border: 1px solid #cde2da;
  border-radius: 13px;
  background: #f1f8f4;
  color: #1b6b59;
  font-size: 13px;
  font-weight: 650;
}

.profile-info-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
}

.info-item {
  min-width: 0;
}

.info-item span {
  display: block;
  color: #8a9792;
  font-size: 12px;
}

.info-item strong {
  display: block;
  margin-top: 3px;
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
  font-size: 14px;
}

.contact-wrap {
  display: grid;
  gap: 10px;
  padding: 14px 0 2px;
}

.contact-button {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  width: 100%;
  min-height: 48px;
  padding: 0 16px;
  border: 0;
  border-radius: var(--radius);
  background: #1682d8;
  color: #fff;
  font-size: 15px;
  font-weight: 750;
  cursor: pointer;
  box-shadow: 0 5px 14px rgba(22, 130, 216, 0.22);
}

.contact-button:disabled {
  background: #d7dedb;
  color: #7e8985;
  cursor: not-allowed;
  box-shadow: none;
}

.contact-button svg {
  width: 18px;
  height: 18px;
}

.contact-button.is-secondary {
  background: #fff;
  border: 1px solid #bfd8cf;
  color: #1f7f67;
  box-shadow: none;
}

.contact-button.is-secondary:hover {
  background: #f0f7f3;
  border-color: #9dc9b7;
}

.toast {
  position: absolute;
  z-index: 1600;
  left: 50%;
  bottom: max(22px, env(safe-area-inset-bottom));
  max-width: min(86vw, 360px);
  padding: 10px 16px;
  border-radius: var(--radius);
  background: rgba(23, 33, 31, 0.94);
  color: #fff;
  font-size: 14px;
  text-align: center;
  transform: translateX(-50%);
  box-shadow: var(--shadow);
}

.map-avatar-icon {
  background: transparent;
  border: 0;
}

.leaflet-popup-content-wrapper {
  border-radius: var(--radius);
  box-shadow: 0 8px 24px rgba(30, 43, 39, 0.18);
}

@media (min-width: 760px) {
  .topbar {
    top: 16px;
    left: 18px;
    right: auto;
    min-width: 280px;
  }

  .people-panel {
    left: auto;
    top: 84px;
    right: 18px;
    bottom: 18px;
    width: 384px;
    height: auto;
    min-height: 0;
  }

  .people-panel.is-compact {
    top: auto;
    height: 146px;
  }

  .profile-sheet {
    inset: 18px;
    max-width: 440px;
    margin: 0 auto;
    border-radius: 12px;
    box-shadow: 0 24px 70px rgba(22, 34, 30, 0.28);
  }
}

@media (min-width: 1180px) {
  .profile-sheet {
    inset: 22px auto 22px calc(100% - 440px - 34px);
    width: 440px;
  }

  .people-panel {
    width: 400px;
  }
}

@media (max-height: 720px) and (max-width: 759px) {
  .people-panel {
    height: min(52dvh, 360px);
  }
}
