/* ------------------------------------------------------------------ */
/* Layout                                                               */
/* ------------------------------------------------------------------ */

/*
 * Desktop: map fills full width; legend floats over the top-right
 * corner as an overlay (position: absolute), so the map is never
 * narrowed. No flex needed on the wrapper.
 */
.khm-layout {
  position: relative;
}

#kingdom-hub-map {
  display: block;
  width: 100%;
  height: 620px;
  border-radius: 12px;
}

.khm-legend-panel {
  position: absolute;
  top: 10px;
  right: 10px;
  z-index: 1000;           /* above Leaflet tiles (400) and controls (800) */
  width: 190px;
  max-height: calc(100% - 20px);
  overflow-y: auto;
  background: rgba(255, 255, 255, 0.96);
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
  border-radius: 10px;
  padding: 10px 12px;
  box-shadow: 0 6px 18px rgba(0, 0, 0, 0.18);
  font-size: 13px;
  line-height: 1.3;
  box-sizing: border-box;
}

/*
 * Mobile: stack the legend below the map as a full-width block.
 */
@media (max-width: 768px) {
  .khm-layout {
    display: flex;
    flex-direction: column;
    gap: 16px;
  }

  .khm-legend-panel {
    position: static;
    width: 100%;
    max-height: none;
    overflow-y: visible;
    backdrop-filter: none;
    -webkit-backdrop-filter: none;
    border: 1px solid rgba(0, 0, 0, 0.08);
  }

  #kingdom-hub-map {
    height: 420px;
  }
}

/* ------------------------------------------------------------------ */
/* Custom pin divIcon                                                   */
/* ------------------------------------------------------------------ */

.khm-pin {
  width: 38px;
  height: 38px;
  border-radius: 19px 19px 19px 0;
  transform: rotate(-45deg);
  position: relative;
  box-shadow: 0 6px 14px rgba(0, 0, 0, 0.25);
  border: 2px solid rgba(0, 0, 0, 0.28);
}

.khm-pin-inner {
  width: 30px;
  height: 30px;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.95);
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%) rotate(45deg);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 2px;
  overflow: hidden;
}

.khm-pin-inner .khm-focus {
  display: flex !important;
  flex-direction: row !important;
  flex-wrap: wrap;
  gap: 2px;
  align-items: center;
  justify-content: center;
  width: 100%;
}

.khm-pin-inner .khm-focus[data-count="1"],
.khm-pin-inner .khm-focus[data-count="2"] {
  flex-wrap: nowrap;
}

.khm-pin-inner .khm-focus[data-count="3"] {
  display: grid !important;
  grid-template-columns: repeat(2, 1fr);
  grid-auto-rows: 1fr;
  gap: 1px;
  place-items: center;
}

.khm-pin-inner .khm-focus[data-count="3"] .khm-focus-icon {
  width: 13px !important;
  height: 13px !important;
  font-size: 12px !important;
}

.khm-pin-inner .khm-focus-icon {
  display: inline-flex !important;
  width: 14px;
  height: 14px;
  align-items: center;
  justify-content: center;
  font-size: 13px;
  line-height: 1;
  vertical-align: middle;
}

/* ------------------------------------------------------------------ */
/* Cluster icon                                                         */
/* ------------------------------------------------------------------ */

.khm-cluster {
  width: 44px;
  height: 44px;
  border-radius: 50%;
  border: 2px solid rgba(0, 0, 0, 0.28);
  box-shadow: 0 6px 14px rgba(0, 0, 0, 0.22);
  display: flex;
  align-items: center;
  justify-content: center;
  position: relative;
}

.khm-cluster::after {
  content: '';
  position: absolute;
  inset: 6px;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.92);
}

.khm-cluster-count {
  position: relative;
  z-index: 2;
  font-weight: 800;
  font-size: 14px;
  color: rgba(0, 0, 0, 0.78);
}

.khm-cluster-mixed {
  position: absolute;
  bottom: -2px;
  right: -2px;
  z-index: 3;
  width: 14px;
  height: 14px;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.95);
  border: 2px solid rgba(0, 0, 0, 0.18);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 11px;
  line-height: 1;
}

/* ------------------------------------------------------------------ */
/* Legend                                                               */
/* ------------------------------------------------------------------ */

.khm-legend-title {
  font-weight: 700;
  margin-bottom: 6px;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  opacity: 0.6;
}

.khm-legend-title + .khm-legend-title,
.khm-legend-focus-section {
  margin-top: 10px;
}

.khm-legend-item {
  display: flex;
  align-items: center;
  gap: 8px;
  margin: 2px 0;
}

.khm-legend-toggle {
  cursor: pointer;
  user-select: none;
  border-radius: 6px;
  padding: 4px 5px;
  transition: background 100ms ease, opacity 150ms ease;
}

.khm-legend-toggle:hover {
  background: rgba(0, 0, 0, 0.06);
}

.khm-legend-toggle.is-off {
  opacity: 0.3;
}

.khm-legend-toggle.is-off .khm-legend-swatch {
  filter: grayscale(1);
}

.khm-legend-swatch {
  width: 11px;
  height: 11px;
  border-radius: 50%;
  border: 2px solid rgba(0, 0, 0, 0.22);
  flex-shrink: 0;
}

/* Hub count + reset row */
.khm-legend-footer {
  margin-top: 10px;
  padding-top: 8px;
  border-top: 1px solid rgba(0, 0, 0, 0.08);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.khm-legend-count {
  font-size: 11px;
  opacity: 0.55;
  white-space: nowrap;
}

.khm-legend-reset {
  font-size: 11px;
  color: inherit;
  opacity: 0.5;
  cursor: pointer;
  border: none;
  background: none;
  padding: 0;
  text-decoration: underline;
  text-underline-offset: 2px;
  white-space: nowrap;
}

.khm-legend-reset:hover {
  opacity: 0.85;
}

/* ------------------------------------------------------------------ */
/* Popup                                                                */
/* ------------------------------------------------------------------ */

.khm-popup-title {
  font-weight: 700;
  font-size: 14px;
  margin-bottom: 5px;
}

.khm-popup-title a {
  text-decoration: none;
  color: inherit;
}

.khm-popup-title a:hover {
  text-decoration: underline;
}

.khm-popup-meta {
  font-size: 12px;
  opacity: 0.75;
  margin: 2px 0;
}

.khm-popup-scope-dot {
  display: inline-block;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  margin-right: 4px;
  vertical-align: middle;
  border: 1px solid rgba(0,0,0,0.2);
}
