:root {
  --bg: #ffffff;
  --fg: #111827;
  --muted: #6b7280;
  --border: #e5e7eb;
  --card: #ffffff;
  --accent: #0b7a4b;
  --accent-fg: #ffffff;
  --warn-bg: #fef3c7;
  --warn-fg: #92400e;
  --shadow: 0 4px 24px rgba(0, 0, 0, 0.14);
  --topbar-h: 56px;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #111418;
    --fg: #e5e7eb;
    --muted: #9ca3af;
    --border: #2a2f36;
    --card: #181c22;
    --accent: #2fb673;
    --accent-fg: #06201a;
    --warn-bg: #3b2f0b;
    --warn-fg: #fcd34d;
    --shadow: 0 4px 24px rgba(0, 0, 0, 0.5);
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  font: 15px/1.4 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  color: var(--fg);
  background: var(--bg);
  overflow: hidden;
}
#map { position: fixed; inset: 0; }

.topbar {
  position: fixed;
  top: 0; left: 0; right: 0;
  height: var(--topbar-h);
  padding: 8px 12px;
  padding-top: calc(8px + env(safe-area-inset-top));
  display: flex;
  gap: 8px;
  align-items: center;
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--border);
  z-index: 10;
}
.brand { color: var(--accent); display: flex; align-items: center; }
#il-select {
  flex: 1;
  min-width: 0;
  height: 40px;
  padding: 0 10px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--card);
  color: var(--fg);
  font: inherit;
}
.btn {
  height: 40px;
  padding: 0 14px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--card);
  color: var(--fg);
  font: inherit;
  font-weight: 600;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  cursor: pointer;
  white-space: nowrap;
}
.btn-primary { background: var(--accent); color: var(--accent-fg); border-color: transparent; }
.btn:disabled { opacity: 0.6; cursor: default; }

.status {
  position: fixed;
  top: calc(var(--topbar-h) + env(safe-area-inset-top) + 8px);
  left: 12px; right: 12px;
  margin: 0 auto;
  max-width: 560px;
  padding: 8px 12px;
  border-radius: 10px;
  background: var(--card);
  color: var(--muted);
  font-size: 13px;
  box-shadow: var(--shadow);
  z-index: 9;
  text-align: center;
}
.status.warn { background: var(--warn-bg); color: var(--warn-fg); }
.status a { color: inherit; }

.sheet {
  position: fixed;
  left: 0; right: 0; bottom: 0;
  max-height: 46vh;
  display: flex;
  flex-direction: column;
  background: var(--card);
  border-radius: 16px 16px 0 0;
  box-shadow: var(--shadow);
  padding-bottom: env(safe-area-inset-bottom);
  z-index: 10;
}
.sheet-handle {
  width: 40px; height: 4px;
  border-radius: 2px;
  background: var(--border);
  margin: 8px auto 4px;
}
.sheet-head {
  padding: 6px 16px 10px;
  font-size: 13px;
  color: var(--muted);
  border-bottom: 1px solid var(--border);
}
.list {
  list-style: none;
  margin: 0; padding: 0;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
}
.item {
  padding: 10px 16px;
  border-bottom: 1px solid var(--border);
  cursor: pointer;
}
.item:hover { background: color-mix(in srgb, var(--accent) 6%, var(--card)); }
.item:hover .item-name { text-decoration: underline; }
.item:active { background: color-mix(in srgb, var(--accent) 14%, var(--card)); }
.item.active { background: color-mix(in srgb, var(--accent) 12%, var(--card)); }
.item-top { display: flex; justify-content: space-between; gap: 8px; align-items: baseline; }
.item-name { font-weight: 600; text-underline-offset: 3px; }
.item-dist { color: var(--muted); font-size: 13px; white-space: nowrap; }
.item-ilce { color: var(--accent); font-size: 13px; font-weight: 600; }
.item-addr { color: var(--muted); font-size: 13px; margin-top: 2px; }
.item-note { color: var(--warn-fg); font-size: 13px; margin-top: 2px; }
.item-actions { display: flex; gap: 8px; margin-top: 8px; }
.item-actions a {
  flex: 1;
  text-align: center;
  padding: 8px 10px;
  border-radius: 8px;
  border: 1px solid var(--border);
  color: var(--fg);
  text-decoration: none;
  font-size: 14px;
  font-weight: 600;
}
.item-actions a.primary { background: var(--accent); color: var(--accent-fg); border-color: transparent; }

.user-dot {
  width: 16px; height: 16px;
  border-radius: 50%;
  background: #2563eb;
  border: 3px solid #fff;
  box-shadow: 0 0 0 6px rgba(37, 99, 235, 0.25);
}

.maplibregl-popup-content {
  background: var(--card);
  color: var(--fg);
  border-radius: 12px;
  padding: 12px 14px;
  box-shadow: var(--shadow);
  min-width: 220px;
}
.maplibregl-popup-tip { border-top-color: var(--card) !important; border-bottom-color: var(--card) !important; }
.maplibregl-popup-close-button { color: var(--muted); font-size: 18px; padding: 4px 8px; }
.popup-name { font-weight: 700; margin-right: 18px; }
.popup-addr { color: var(--muted); font-size: 13px; margin-top: 2px; }
.popup-actions { display: flex; gap: 8px; margin-top: 10px; }
.popup-actions a {
  flex: 1; text-align: center; padding: 7px 8px; border-radius: 8px;
  border: 1px solid var(--border); color: var(--fg); text-decoration: none; font-size: 13px; font-weight: 600;
}
.popup-actions a.primary { background: var(--accent); color: var(--accent-fg); border-color: transparent; }

.maplibregl-ctrl-top-right { top: calc(var(--topbar-h) + env(safe-area-inset-top) + 8px); }
.maplibregl-ctrl-bottom-left, .maplibregl-ctrl-bottom-right { bottom: 46vh; }

@media (min-width: 900px) {
  .sheet {
    top: calc(var(--topbar-h) + 12px);
    bottom: 12px; left: 12px; right: auto;
    width: 380px;
    max-height: none;
    border-radius: 16px;
  }
  .sheet-handle { display: none; }
  .status { left: 404px; right: 12px; margin: 0; }
  .maplibregl-ctrl-bottom-left, .maplibregl-ctrl-bottom-right { bottom: 0; }
  .maplibregl-ctrl-bottom-left { left: 404px; }
}
