:root {
  --brand: #005eb8;
  --brand-700: #00386e;
  --brand-50: #e8f4ff;
  --accent: #00a3e0;
  --accent-dark: #007aa8;
  --gold: #f5b942;
  --gold-dark: #b7791f;
  --coral: #e04e2e;
  --ink: #0b1b2b;
  --muted: #5b6b7c;
  --line: #dce6ef;
  --plate: #fbfaf7;
  --site: #eaf0f5;
  --panel: #ffffff;
  --radius: 14px;
  --shadow: 0 12px 32px rgba(11, 27, 43, 0.14);
  --shadow-soft: 0 2px 8px rgba(11, 27, 43, 0.1);
  --font-ui: "Inter", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --font-display: "Outfit", "Inter", system-ui, sans-serif;
  --font-mono: ui-monospace, "SFMono-Regular", Menlo, Consolas, monospace;
  font-family: var(--font-ui);
  color: var(--ink);
  -webkit-font-smoothing: antialiased;
}

* { box-sizing: border-box; }

html, body { margin: 0; height: 100%; background: var(--site); }

body {
  font-family: var(--font-ui);
  font-size: 15px;
  line-height: 1.45;
}

button { font: inherit; }

#app { display: flex; height: 100%; overflow: hidden; }

svg {
  width: 20px;
  height: 20px;
  fill: none;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}

/* ---------- Directory panel ---------- */

#panel {
  width: clamp(320px, 24vw, 400px);
  flex: none;
  display: flex;
  flex-direction: column;
  min-height: 0;
  background: var(--panel);
  border-right: 1px solid var(--line);
  z-index: 2;
}

.panel-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 16px 18px 12px;
}

.panel-heading h1 {
  margin: 0;
  font-family: var(--font-display);
  font-size: 20px;
  font-weight: 700;
  letter-spacing: -0.01em;
  color: var(--ink);
}

.panel-heading p {
  margin: 2px 0 0;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.09em;
  text-transform: uppercase;
  color: var(--muted);
}

.search {
  display: flex;
  align-items: center;
  gap: 9px;
  margin: 0 16px 12px;
  padding: 0 12px;
  min-height: 44px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: #fff;
  color: var(--muted);
}

.search:focus-within {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(0, 163, 224, 0.18);
}

.search input {
  flex: 1;
  min-width: 0;
  border: 0;
  outline: 0;
  background: transparent;
  padding: 11px 0;
  font-family: var(--font-ui);
  font-size: 14px;
  color: var(--ink);
}

.search input::placeholder { color: #8595a5; }

.zones {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 4px;
  margin: 0 16px 12px;
  padding: 3px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: #f4f8fb;
}

.zone {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  min-height: 34px;
  padding: 4px 6px;
  border: 0;
  border-radius: 7px;
  background: transparent;
  color: var(--muted);
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
  white-space: nowrap;
}

.zone:hover { color: var(--brand-700); }

.zone[aria-pressed="true"] {
  background: var(--brand-700);
  color: #fff;
  box-shadow: var(--shadow-soft);
}

.zone-count {
  font-family: var(--font-mono);
  font-size: 10px;
  font-weight: 500;
  opacity: 0.7;
}

.filters {
  display: flex;
  gap: 6px;
  padding: 0 16px 12px;
  border-bottom: 1px solid var(--line);
  overflow-x: auto;
  scrollbar-width: none;
  -webkit-mask-image: linear-gradient(to right, #000 92%, transparent);
  mask-image: linear-gradient(to right, #000 92%, transparent);
}

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

.chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  flex: none;
  min-height: 32px;
  padding: 5px 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  color: var(--ink);
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
  white-space: nowrap;
}

.chip:hover { border-color: #b9cbdb; }

.chip .dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
}

.chip[aria-pressed="true"] {
  background: var(--brand-50);
  border-color: #8fc7ff;
  color: var(--brand-700);
  box-shadow: inset 0 0 0 1px rgba(0, 94, 184, 0.12);
}

.results {
  list-style: none;
  margin: 0;
  padding: 0 8px 18px;
  overflow-y: auto;
  flex: 1;
  min-height: 0;
  scroll-padding-top: 32px;
}

.group-head {
  position: sticky;
  top: 0;
  z-index: 1;
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 8px;
  margin: 0;
  padding: 12px 10px 6px;
  background: linear-gradient(#fff 70%, rgba(255, 255, 255, 0));
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.11em;
  text-transform: uppercase;
  color: var(--muted);
}

.group-head .group-count {
  font-family: var(--font-mono);
  font-size: 10px;
  font-weight: 500;
  letter-spacing: 0;
  color: #8595a5;
}

.result {
  display: flex;
  align-items: center;
  gap: 11px;
  width: 100%;
  padding: 8px 10px;
  border: 0;
  border-radius: 9px;
  background: transparent;
  text-align: left;
  cursor: pointer;
  color: inherit;
}

.result:hover,
.result:focus-visible {
  background: #f2f7fb;
  outline: none;
}

.result:focus-visible {
  box-shadow: inset 0 0 0 2px var(--accent);
}

.result.selected {
  background: var(--brand-50);
  box-shadow: inset 3px 0 0 var(--brand);
}

.result-ref {
  flex: none;
  display: grid;
  place-items: center;
  min-width: 34px;
  height: 34px;
  padding: 0 4px;
  border-radius: 8px;
  background: #f4f8fb;
  border: 1px solid #e3edf5;
  font-family: var(--font-mono);
  font-size: 11px;
  font-weight: 600;
  color: var(--brand-700);
}

.result.selected .result-ref {
  background: #fff;
  border-color: #b9d8f5;
}

.result-icon {
  flex: none;
  display: grid;
  place-items: center;
  width: 32px;
  height: 32px;
  border-radius: 8px;
  color: #fff;
}

.result-icon svg { width: 17px; height: 17px; }

.result-text { min-width: 0; flex: 1; }

.result-text strong {
  display: block;
  font-size: 13.5px;
  font-weight: 600;
  color: var(--ink);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.result-text span {
  display: block;
  margin-top: 1px;
  font-size: 11.5px;
  color: var(--muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.results .empty {
  padding: 28px 14px;
  color: var(--muted);
  text-align: center;
  font-size: 13px;
}

/* ---------- Map stage ---------- */

#stage {
  position: relative;
  flex: 1;
  min-width: 0;
  background:
    radial-gradient(120% 90% at 50% 0%, #f3f7fa 0%, var(--site) 58%, #e2eaf1 100%);
}

#viewport { position: absolute; inset: 0; z-index: 0; }

#viewport canvas { display: block; outline: none; cursor: grab; }
#viewport canvas.dragging { cursor: grabbing !important; }
#viewport canvas:focus-visible { outline: 2px solid var(--accent); outline-offset: -4px; }

.hint {
  position: absolute;
  top: 16px;
  left: 50%;
  transform: translateX(-50%);
  padding: 7px 14px;
  border-radius: 999px;
  background: rgba(11, 27, 43, 0.82);
  color: #fff;
  font-size: 12px;
  font-weight: 500;
  white-space: nowrap;
  pointer-events: none;
  z-index: 1;
  transition: opacity 0.5s;
}

.hint.gone { opacity: 0; }
.hint .touch { display: none; }

@media (pointer: coarse) {
  .hint .mouse { display: none; }
  .hint .touch { display: inline; }
}

.labels-layer { position: absolute; inset: 0; pointer-events: none; }

.map-controls {
  position: absolute;
  top: 16px;
  right: 16px;
  display: flex;
  flex-direction: column;
  gap: 6px;
  padding: 4px;
  border-radius: 12px;
  background: rgba(255, 255, 255, 0.92);
  border: 1px solid var(--line);
  box-shadow: var(--shadow-soft);
  backdrop-filter: blur(6px);
  z-index: 2;
}

.control-button {
  width: 38px;
  height: 38px;
  display: grid;
  place-items: center;
  border: 0;
  border-radius: 8px;
  background: transparent;
  font-size: 18px;
  font-weight: 600;
  color: var(--brand-700);
  cursor: pointer;
}

.control-button:hover { background: var(--brand-50); }
.control-button:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }

#view-toggle {
  font-family: var(--font-mono);
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.02em;
}

#view-toggle[aria-pressed="true"] {
  background: var(--brand-700);
  color: #fff;
}

.compass {
  position: absolute;
  right: 20px;
  bottom: 20px;
  width: 44px;
  height: 44px;
  border-radius: 50%;
  background: #fff;
  border: 1px solid var(--line);
  box-shadow: var(--shadow-soft);
  z-index: 2;
}

.compass-needle { position: absolute; inset: 0; display: flex; justify-content: center; }

.compass-needle::before {
  content: "";
  position: absolute;
  top: 8px;
  left: 50%;
  width: 0;
  height: 0;
  margin-left: -5px;
  border-left: 5px solid transparent;
  border-right: 5px solid transparent;
  border-bottom: 14px solid var(--coral);
}

.compass-needle::after {
  content: "";
  position: absolute;
  bottom: 8px;
  left: 50%;
  width: 0;
  height: 0;
  margin-left: -5px;
  border-left: 5px solid transparent;
  border-right: 5px solid transparent;
  border-top: 14px solid #cbd5e1;
}

.compass-needle span {
  position: absolute;
  top: -13px;
  font-size: 10px;
  font-weight: 700;
  color: var(--coral);
}

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

.legend {
  position: absolute;
  left: 16px;
  bottom: 16px;
  width: 268px;
  padding: 12px 14px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: rgba(255, 255, 255, 0.94);
  box-shadow: var(--shadow-soft);
  backdrop-filter: blur(6px);
  z-index: 2;
}

.legend-title {
  margin: 0 0 8px;
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.11em;
  text-transform: uppercase;
  color: var(--muted);
}

.legend-items {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 5px 12px;
}

.legend-item {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 11.5px;
  font-weight: 500;
  color: var(--ink);
}

.legend-swatch {
  width: 10px;
  height: 10px;
  border-radius: 3px;
  flex: none;
}

/* ---------- Details ---------- */

.details {
  position: absolute;
  left: 16px;
  bottom: 16px;
  width: min(360px, calc(100% - 100px));
  padding: 16px 18px;
  border-radius: var(--radius);
  border: 1px solid var(--line);
  background: #fff;
  box-shadow: var(--shadow);
  z-index: 3;
}

.details h2 {
  margin: 8px 30px 4px 0;
  font-family: var(--font-display);
  font-size: 21px;
  font-weight: 700;
  letter-spacing: -0.01em;
}

.details p { margin: 4px 0; font-size: 13px; line-height: 1.5; }

.details-image {
  display: block;
  width: 100%;
  max-height: 92px;
  object-fit: contain;
  margin: 8px 0 4px;
  border-radius: 8px;
  background: #f6f9fc;
}

.details-hours { font-weight: 600; color: #047857; }
.details-phone a, .details-website a { color: var(--brand-700); font-weight: 600; }
.details-ref {
  color: var(--muted);
  font-family: var(--font-mono);
  font-size: 11px !important;
}

.details-close { position: absolute; top: 8px; right: 8px; }

.details-badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 3px 9px;
  border-radius: 6px;
  color: #fff;
  font-size: 10.5px;
  font-weight: 700;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

.details-badge svg { width: 13px; height: 13px; }

.icon-button {
  display: grid;
  place-items: center;
  width: 34px;
  height: 34px;
  border: 0;
  border-radius: 50%;
  background: transparent;
  color: inherit;
  cursor: pointer;
}

.icon-button:hover { background: rgba(127, 127, 127, 0.12); }
.icon-button:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }

/* ---------- Loading and fallback ---------- */

.loading {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  background: var(--site);
  color: var(--muted);
  font-size: 13px;
  font-weight: 500;
  z-index: 4;
}

.loading-spinner {
  width: 16px;
  height: 16px;
  border-radius: 50%;
  border: 2px solid #c7d5e1;
  border-top-color: var(--brand);
  animation: spin 0.8s linear infinite;
}

@keyframes spin { to { transform: rotate(360deg); } }

.fallback {
  position: absolute;
  inset: 0;
  display: grid;
  place-content: center;
  justify-items: center;
  gap: 6px;
  padding: 32px;
  text-align: center;
  background: var(--site);
  z-index: 4;
}

.fallback[hidden] { display: none; }
.fallback-title { margin: 0; font-family: var(--font-display); font-size: 20px; font-weight: 700; }
.fallback p { max-width: 42ch; margin: 0; color: var(--muted); font-size: 13px; }
.fallback a {
  margin-top: 10px;
  padding: 10px 14px;
  border-radius: 8px;
  background: var(--brand-700);
  color: #fff;
  font-size: 13px;
  font-weight: 600;
  text-decoration: none;
}

/* ---------- Labels drawn over the 3D view ---------- */

.pin {
  display: grid;
  place-items: center;
  width: 28px;
  height: 28px;
  border-radius: 50%;
  border: 2px solid #fff;
  color: #fff;
  box-shadow: 0 3px 8px rgba(11, 27, 43, 0.28);
  cursor: pointer;
  pointer-events: auto;
  transition: transform 0.15s;
}

.pin svg { width: 15px; height: 15px; }
.pin:hover, .pin.selected { transform: scale(1.22); }
.pin.dimmed { opacity: 0.18; pointer-events: none; }

.unit-label {
  display: flex;
  align-items: center;
  gap: 5px;
  padding: 3px 8px 3px 3px;
  border-radius: 6px;
  border: 1px solid rgba(220, 230, 239, 0.9);
  background: rgba(255, 255, 255, 0.95);
  box-shadow: 0 1px 4px rgba(11, 27, 43, 0.14);
  font-size: 11.5px;
  font-weight: 600;
  color: var(--ink);
  white-space: nowrap;
  cursor: pointer;
  pointer-events: auto;
}

.unit-label .badge {
  display: grid;
  place-items: center;
  width: 20px;
  height: 20px;
  border-radius: 4px;
  color: #fff;
}

.unit-label .badge svg { width: 11px; height: 11px; }

.unit-label strong {
  font-family: var(--font-mono);
  font-size: 9.5px;
  font-weight: 600;
  color: var(--muted);
  margin-right: 1px;
}

.unit-label .name-text {
  display: inline-block;
  max-width: 132px;
  overflow: hidden;
  text-overflow: ellipsis;
  vertical-align: bottom;
}

.unit-label.gate-label {
  padding: 2px 5px 2px 2px;
  font-size: 10.5px;
  font-family: var(--font-mono);
  font-weight: 600;
  letter-spacing: 0.01em;
}

.unit-label.collapsed { display: none; }

.unit-label.icon-only { padding: 3px; }
.unit-label.compact { padding: 2px 5px 2px 2px; gap: 3px; }
.unit-label.compact .name-text { display: none; }
.unit-label.compact strong { margin-right: 0; }
.unit-label.compact:hover .name-text { display: inline; margin-left: 3px; }
.unit-label.dimmed { opacity: 0.12; pointer-events: none; }
.unit-label.hidden { display: none; }
.unit-label.selected {
  border-color: var(--gold);
  box-shadow: 0 0 0 2px rgba(245, 185, 66, 0.45), 0 2px 8px rgba(11, 27, 43, 0.2);
}

.only-mobile { display: none; }

/* ---------- Small screens: directory becomes a bottom sheet ---------- */

@media (max-width: 760px) {
  #app { flex-direction: column-reverse; }

  #panel {
    width: 100%;
    max-height: 52vh;
    border-right: 0;
    border-top: 1px solid var(--line);
    border-radius: 16px 16px 0 0;
    box-shadow: 0 -10px 28px rgba(11, 27, 43, 0.14);
    transition: max-height 0.25s ease;
  }

  #panel.collapsed { max-height: 118px; }
  #panel.collapsed .filters,
  #panel.collapsed .results,
  #panel.collapsed .zones { display: none; }

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

  .panel-header { padding: 12px 16px 8px; }
  .only-mobile { display: grid; }

  #stage { flex: 1; min-height: 0; }

  .legend { display: none; }

  .details {
    left: 12px;
    right: 12px;
    bottom: 12px;
    width: auto;
    max-height: 46vh;
    overflow-y: auto;
  }

  .compass {
    top: 14px;
    left: 14px;
    right: auto;
    bottom: auto;
    width: 40px;
    height: 40px;
  }

  .map-controls { top: 14px; right: 14px; }
  .hint { display: none; }
}

@media (prefers-reduced-motion: reduce) {
  * { animation-duration: 0.01ms !important; transition-duration: 0.01ms !important; }
}
