:root {
  --navy: #0c2d48;
  --navy-deep: #071e30;
  --teal: #0d9488;
  --teal-hover: #0f766e;
  --teal-soft: rgba(13, 148, 136, 0.13);
  --amber: #f97316;
  --glass: rgba(255, 255, 255, 0.9);
  --glass-strong: rgba(255, 255, 255, 0.96);
  --border: rgba(15, 23, 42, 0.1);
  --text: #0f172a;
  --muted: #475569;
  --subtle: #64748b;
  --shadow: 0 12px 32px rgba(7, 30, 48, 0.16), 0 2px 6px rgba(7, 30, 48, 0.08);
  --radius: 16px;
}

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

html,
body,
#map {
  width: 100%;
  height: 100%;
  overflow: hidden;
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  color: var(--text);
  background: #0b2538;
  -webkit-font-smoothing: antialiased;
}

.hidden {
  display: none !important;
}

/* Floating top-left control panel */
.panel {
  position: fixed;
  top: 16px;
  left: 16px;
  width: 392px;
  max-width: calc(100vw - 32px);
  background: var(--glass);
  backdrop-filter: blur(18px) saturate(1.4);
  -webkit-backdrop-filter: blur(18px) saturate(1.4);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  z-index: 20;
  padding: 14px;
  transition: transform 0.2s ease, opacity 0.2s ease;
}

.panel-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 11px;
  text-decoration: none;
  color: inherit;
}

.brand-icon {
  flex-shrink: 0;
  border-radius: 9px;
  box-shadow: 0 2px 8px rgba(12, 45, 72, 0.2);
}

.brand-text h1 {
  font-size: 16px;
  font-weight: 700;
  letter-spacing: -0.02em;
  color: var(--navy);
  line-height: 1.15;
}

.subtitle {
  display: block;
  font-size: 12px;
  font-weight: 500;
  color: var(--subtle);
  margin-top: 1px;
}

.icon-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 32px;
  border: none;
  border-radius: 9px;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
  transition: background 0.15s ease, color 0.15s ease;
}

.icon-btn:hover {
  background: rgba(15, 23, 42, 0.07);
  color: var(--text);
}

.mobile-toggle {
  display: none;
}

.panel-body {
  margin-top: 12px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

/* Search */
.search-row {
  position: relative;
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 8px;
  align-items: center;
}

.search-wrap {
  position: relative;
  min-width: 0;
}

.search-icon {
  position: absolute;
  left: 11px;
  top: 50%;
  transform: translateY(-50%);
  color: var(--subtle);
  pointer-events: none;
}

#search-input {
  width: 100%;
  height: 38px;
  padding: 0 34px 0 34px;
  border-radius: 10px;
  border: 1px solid rgba(15, 23, 42, 0.12);
  background: rgba(255, 255, 255, 0.88);
  font-family: inherit;
  font-size: 13.5px;
  color: var(--text);
  outline: none;
  transition: border-color 0.15s ease, box-shadow 0.15s ease, background 0.15s ease;
}

#search-input:focus {
  border-color: var(--teal);
  background: #ffffff;
  box-shadow: 0 0 0 3px rgba(13, 148, 136, 0.16);
}

#search-input::-webkit-search-cancel-button {
  -webkit-appearance: none;
}

.clear-btn {
  position: absolute;
  right: 6px;
  top: 50%;
  transform: translateY(-50%);
  width: 24px;
  height: 24px;
  border: none;
  border-radius: 6px;
  background: transparent;
  color: var(--subtle);
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.clear-btn:hover {
  background: rgba(15, 23, 42, 0.08);
  color: var(--text);
}

.search-results {
  position: absolute;
  top: calc(100% + 8px);
  left: 0;
  right: 0;
  max-height: 320px;
  overflow-y: auto;
  list-style: none;
  background: var(--glass-strong);
  backdrop-filter: blur(18px);
  -webkit-backdrop-filter: blur(18px);
  border: 1px solid var(--border);
  border-radius: 12px;
  box-shadow: var(--shadow);
  padding: 5px;
  z-index: 40;
}

.search-results li {
  display: flex;
  flex-direction: column;
  gap: 2px;
  padding: 8px 11px;
  border-radius: 8px;
  cursor: pointer;
  transition: background 0.12s ease;
}

.search-results li:hover,
.search-results li.active {
  background: var(--teal-soft);
}

.search-results .res-name {
  font-size: 13.5px;
  font-weight: 600;
  color: var(--navy);
  line-height: 1.3;
}

.search-results .res-region {
  font-size: 11.5px;
  color: var(--subtle);
  line-height: 1.25;
}

.search-results .res-empty {
  color: var(--subtle);
  cursor: default;
  align-items: center;
  padding: 12px;
  font-size: 13px;
}

/* Filters */
.filter-row {
  display: flex;
  align-items: center;
  gap: 8px;
}

.filter-row.split {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 8px;
}

.segmented {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  width: 100%;
  background: rgba(15, 23, 42, 0.06);
  border-radius: 10px;
  padding: 3px;
  gap: 2px;
}

.seg-btn {
  border: none;
  background: transparent;
  padding: 6px 8px;
  border-radius: 7.5px;
  font-family: inherit;
  font-size: 12.5px;
  font-weight: 600;
  color: var(--muted);
  cursor: pointer;
  transition: background 0.15s ease, color 0.15s ease, box-shadow 0.15s ease;
}

.seg-btn.active {
  background: #ffffff;
  color: var(--navy);
  box-shadow: 0 1px 4px rgba(15, 23, 42, 0.12);
}

#region-select {
  height: 36px;
  padding: 0 10px;
  border-radius: 10px;
  border: 1px solid rgba(15, 23, 42, 0.12);
  background: rgba(255, 255, 255, 0.88);
  font-family: inherit;
  font-size: 12.5px;
  font-weight: 500;
  color: var(--text);
  outline: none;
  cursor: pointer;
  min-width: 0;
}

#region-select:focus {
  border-color: var(--teal);
}

.action-pill {
  height: 38px;
  padding: 0 12px;
  border-radius: 10px;
  border: 1px solid rgba(13, 148, 136, 0.25);
  background: var(--teal-soft);
  color: var(--teal-hover);
  font-family: inherit;
  font-size: 12.5px;
  font-weight: 600;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  flex-shrink: 0;
  transition: background 0.15s ease, color 0.15s ease, transform 0.1s ease;
}

.action-pill:hover {
  background: var(--teal);
  color: #ffffff;
}

.action-pill:disabled {
  opacity: 0.6;
  cursor: wait;
}

/* Basemap Switcher */
.basemap-switcher {
  position: fixed;
  bottom: 24px;
  left: 16px;
  display: inline-flex;
  gap: 3px;
  padding: 4px;
  background: var(--glass);
  backdrop-filter: blur(16px) saturate(1.4);
  -webkit-backdrop-filter: blur(16px) saturate(1.4);
  border: 1px solid var(--border);
  border-radius: 12px;
  box-shadow: var(--shadow);
  z-index: 15;
}

.basemap-btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 7px 11px;
  border: none;
  border-radius: 8.5px;
  background: transparent;
  font-family: inherit;
  font-size: 12.5px;
  font-weight: 600;
  color: var(--muted);
  cursor: pointer;
  transition: background 0.15s ease, color 0.15s ease;
}

.basemap-btn:hover {
  color: var(--text);
  background: rgba(15, 23, 42, 0.05);
}

.basemap-btn.active {
  background: var(--navy);
  color: #ffffff;
}

/* Detail Card */
.detail-card {
  position: fixed;
  bottom: 24px;
  right: 16px;
  width: 344px;
  max-width: calc(100vw - 32px);
  background: var(--glass-strong);
  backdrop-filter: blur(20px) saturate(1.5);
  -webkit-backdrop-filter: blur(20px) saturate(1.5);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 16px;
  z-index: 25;
  display: flex;
  flex-direction: column;
  gap: 12px;
  animation: slideUp 0.18s ease-out;
}

@keyframes slideUp {
  from {
    opacity: 0;
    transform: translateY(10px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.detail-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 10px;
}

.detail-badges {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-bottom: 5px;
}

.badge {
  display: inline-flex;
  align-items: center;
  padding: 2px 8px;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.01em;
}

.badge.region {
  background: var(--teal-soft);
  color: var(--teal-hover);
}

.badge.distance {
  background: rgba(249, 115, 22, 0.13);
  color: #c2410c;
}

.detail-card h2 {
  font-size: 17px;
  font-weight: 700;
  color: var(--navy);
  letter-spacing: -0.02em;
  line-height: 1.25;
}

.coords-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 8px 10px;
  border-radius: 10px;
  background: rgba(15, 23, 42, 0.045);
  border: 1px solid rgba(15, 23, 42, 0.06);
}

.coords-row code {
  font-family: 'JetBrains Mono', ui-monospace, SFMono-Regular, monospace;
  font-size: 12px;
  color: var(--muted);
}

.mini-btn {
  border: none;
  background: #ffffff;
  color: var(--navy);
  font-family: inherit;
  font-size: 11.5px;
  font-weight: 600;
  padding: 4px 9px;
  border-radius: 6px;
  cursor: pointer;
  box-shadow: 0 1px 2px rgba(15, 23, 42, 0.08);
}

.mini-btn:hover {
  background: var(--navy);
  color: #ffffff;
}

.primary-btn {
  width: 100%;
  height: 40px;
  border: none;
  border-radius: 10px;
  background: linear-gradient(135deg, var(--navy) 0%, var(--teal) 100%);
  color: #ffffff;
  font-family: inherit;
  font-size: 13.5px;
  font-weight: 600;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  box-shadow: 0 4px 12px rgba(13, 148, 136, 0.28);
  transition: transform 0.12s ease, box-shadow 0.15s ease, filter 0.15s ease;
}

.primary-btn:hover {
  filter: brightness(1.06);
  box-shadow: 0 6px 16px rgba(13, 148, 136, 0.36);
}

.primary-btn:active {
  transform: scale(0.99);
}

.link-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 7px;
}

.ext-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  height: 34px;
  border-radius: 9px;
  border: 1px solid rgba(15, 23, 42, 0.11);
  background: #ffffff;
  color: var(--navy);
  text-decoration: none;
  font-family: inherit;
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.15s ease, border-color 0.15s ease;
}

.ext-btn:hover {
  background: rgba(15, 23, 42, 0.04);
  border-color: rgba(15, 23, 42, 0.22);
}

.nearby-section {
  border-top: 1px solid rgba(15, 23, 42, 0.08);
  padding-top: 10px;
}

.nearby-section h3 {
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--subtle);
  margin-bottom: 6px;
}

.nearby-list {
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.nearby-list li button {
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 6px 8px;
  border: none;
  border-radius: 8px;
  background: transparent;
  font-family: inherit;
  font-size: 12.5px;
  color: var(--text);
  cursor: pointer;
  text-align: left;
  transition: background 0.12s ease;
}

.nearby-list li button:hover {
  background: var(--teal-soft);
}

.nearby-name {
  font-weight: 500;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.nearby-dist {
  font-family: 'JetBrains Mono', monospace;
  font-size: 11.5px;
  color: var(--subtle);
  flex-shrink: 0;
}

/* Hover popup */
.maplibregl-popup-content {
  padding: 6px 10px !important;
  border-radius: 8px !important;
  font-family: 'Inter', sans-serif !important;
  font-size: 12.5px !important;
  font-weight: 600 !important;
  color: var(--navy) !important;
  box-shadow: 0 4px 14px rgba(7, 30, 48, 0.2) !important;
  border: 1px solid rgba(15, 23, 42, 0.08);
}

.maplibregl-ctrl-group {
  border-radius: 12px !important;
  overflow: hidden;
  box-shadow: var(--shadow) !important;
  border: 1px solid var(--border) !important;
}

.maplibregl-ctrl-attrib {
  font-size: 10.5px !important;
  background: rgba(255, 255, 255, 0.78) !important;
  backdrop-filter: blur(8px);
}

/* Toast */
.toast {
  position: fixed;
  top: 16px;
  left: 50%;
  transform: translateX(-50%);
  background: var(--navy-deep);
  color: #ffffff;
  padding: 9px 16px;
  border-radius: 999px;
  font-size: 13px;
  font-weight: 500;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.28);
  z-index: 60;
}

/* Mobile responsiveness */
@media (max-width: 680px) {
  .panel {
    top: 10px;
    left: 10px;
    right: 10px;
    width: auto;
    max-width: none;
    padding: 12px;
  }

  .mobile-toggle {
    display: inline-flex;
  }

  .panel.collapsed .panel-body {
    display: none;
  }

  .panel.collapsed .mobile-toggle svg {
    transform: rotate(180deg);
  }

  .basemap-switcher {
    bottom: 14px;
    left: 10px;
  }

  .basemap-btn {
    padding: 6px 9px;
    font-size: 12px;
  }

  .detail-card {
    left: 10px;
    right: 10px;
    bottom: 10px;
    width: auto;
    max-width: none;
    max-height: 55vh;
    overflow-y: auto;
  }
}
